【问题标题】:'/data/anr/traces.txt': Permission denied'/data/anr/traces.txt':权限被拒绝
【发布时间】:2012-01-17 03:04:17
【问题描述】:

我一直在尝试各种网站上显示的关于使用 php 将 MySQL 数据库连接到 android 的教程。我不知道我下面的代码有什么问题。谁能告诉我我需要做什么。

我有这个问题:不幸的是,城市已经停止了

IN LOGCAT : 01-17 02:57:18.790: E/dalvikvm(325): 无法打开堆栈跟踪文件“/data/anr/traces.txt”:权限被拒绝

这是我的 php 代码

<?php
mysql_connect("localhost","???????????","......;");
mysql_select_db("???????????");
$sql=mysql_query("select * from users");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>

city.java

package com.android.City;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.net.ParseException;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class city extends ListActivity {

JSONArray jArray;
String result = null;
InputStream is = null;
StringBuilder sb=null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

 ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//http post
try{
     HttpClient httpclient = new DefaultHttpClient();
     HttpPost httppost = new HttpPost("http://www.estm2011.org/check.php");
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     HttpResponse response = httpclient.execute(httppost);
     HttpEntity entity = response.getEntity();
     is = entity.getContent();
     }catch(Exception e){
         Log.e("log_tag", "Error in http connection"+e.toString());
    }
//convert response to string
try{
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
       sb = new StringBuilder();
       sb.append(reader.readLine() + "\n");

       String line="0";
       while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
        }
        is.close();
        result=sb.toString();
        }catch(Exception e){
              Log.e("log_tag", "Error converting result "+e.toString());
        }
//paring data
String login;
String pass;
try{
      jArray = new JSONArray(result);
      JSONObject json_data=null;
      for(int i=0;i<jArray.length();i++){
             json_data = jArray.getJSONObject(i);
             login=json_data.getString("LOGIN");
             pass=json_data.getString("PASSWORD");
         }
      }
      catch(JSONException e1){
          Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
      } catch (ParseException e1) {
            e1.printStackTrace();
    }
}
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.City"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".CityActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • 您可以从 DDMS 发布您的日志以澄清您的问题吗?
  • 这不是您程序中的实际问题,而只是崩溃报告子系统中的一个烦人的配置错误。使用 logcat 查找并修复实际问题,由于您的程序,您将不再看到此问题,但在其他程序崩溃时仍然可能发生。

标签: php android mysql http


【解决方案1】:

您可以使用adb shell 进入文件夹/data/anr 来检查您的文件权限。

如果权限是root,也许你需要以root用户身份运行或root你的设备。

【讨论】:

  • 我使用windows并登录root
  • 与设备上的 root 不同。
【解决方案2】:

您的应用程序不被视为根应用程序,您无法从应用程序的角度查看它,您必须使应用程序层(也称为“用户”)可以查看文件。或者,如果您愿意,您可能具有与系统相同的 PID。以先到者为准。

【讨论】:

  • 你需要看看linux是如何管理权限的。这将为您提供指导,因为您是设备上的 root,您可以更改权限以满足您的需要。
  • 我使用的是 windows vista 而不是 linux
  • 我使用 ddms 文件资源管理器,但我看不到文件 traces.txt
  • data/anr 有权限 drwxrwx--x
  • 您需要更改该文件的权限.. 通过进入手机 (adb shell) 并导航到目录并更改权限。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
  • 2015-08-30
相关资源
最近更新 更多