0

[NOTE] attach of thread 'binder thread #3' failed this apears in my logcat I dont know what to do with this. Can you solve this for me? I'm creating an output of my database on listview in android.

LogCat:

07-16 04:22:47.018: D/AndroidRuntime(495): Shutting down VM
07-16 04:22:47.068: D/dalvikvm(495): Debugger has detached; object registry had 1 entries
07-16 04:22:47.098: I/AndroidRuntime(495): NOTE: attach of thread 'Binder Thread #3' failed
07-16 04:22:48.338: I/ActivityManager(58): Displayed activity com.database_demo/.Database_demo: 1340 ms (total 50689 ms)

My Java Code:

package com.database_demo;

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

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.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Database_demo extends ListActivity {
ListView list;
List<String> items = new ArrayList<String>();
String result = null;
InputStream is = null;;
StringBuilder sb = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    list = (ListView)findViewById(android.R.id.list);



    items.add("Employ");

    try{

    //http post
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://192.168.0.2/ListView/wa.php");
    List<NameValuePair> nameValue=new ArrayList<NameValuePair>();
    httppost.setEntity(new UrlEncodedFormEntity(nameValue));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    }
    catch(Exception e){
        Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
   }

    //Convert response to string  
    try
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"), 8192);

      sb = new StringBuilder();

      String line = null;

      while ((line = reader.readLine()) != null) 
      {
         sb.append(line + "\n");
      }

      is.close();

      result = sb.toString();
    }
    catch(Exception e)
    {
        Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
    }
    //END Convert response to string  
    String Cat;
    try{
            JSONArray jArray = new JSONArray(result);
            JSONObject json_data=null;
            for(int i=0;i<jArray.length();i++)
            {
               json_data = jArray.getJSONObject(i);
               Cat=json_data.getString("category");
               items.add("Category: " + Cat);
           }
        setupList();
        }
        catch(JSONException e1){
            Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
        } catch (ParseException e1) {
            Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
    }

}
private void setupList(){
    list.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, items));
}
}

my PHP code:

<? 
mysql_connect("localhost","root","");
mysql_select_db("deal");
$q=mysql_query("SELECT * FROM category");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
4

0 回答 0