2012-01-18 96 views
0

我一直在试用各种网站上显示的使用PHP连接到MySQL数据库的教程。我不知道下面的代码有什么问题。任何人都可以告诉我我需要做什么。'traces.txt':权限被拒绝

IHAVE这个问题:不幸的是,该市已停止

在logcat的:2月1日至17日:57:18.790:E/dalvikvm(325):无法打开堆栈跟踪文件“/数据/ ANR/traces.txt“:权限被拒绝

我尝试CHANE权限,但我不能因为IAM在AVD

不是root这是我的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> 
+0

这是不是在你的程序中的实际问题之后。您的程序(或可能是某个与电话无关的程序)因其他原因而崩溃。这个消息因为android bug报告机制中的配置错误而发生。查找并修复您的实际问题,并忽略此问题。 – 2014-03-28 17:29:02

回答

0

将这个线整理你的应用程序标签

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission> 
+0

NOT WORKING bro – 2012-01-18 11:31:50

+0

哦,在这里你使用的是InputStream,所以我认为可能需要使用HttpConnection的setDoInput(true)。 – Lucifer 2012-01-18 11:37:10

+0

可以请更explean或更改代码我谢谢 – 2012-01-18 11:46:27