«

»

10 Feb

Android : Connecting to MySQL using PHP

The main reason for taking a scripting language like PHP is because of the interaction with databases it can offer. In this tutorial I will show you how to use PHP and the MySQL database to retrieve information from the server. For making connection to PHP script, we will  use HTTP protocol from the android system. To implement this tutorial you should have basic knowledge of how to run PHP script and start server.  If we talk about client-server architecture, client is Android device and in server side there is a combination of PHP Script and MySQL. In short, PHP Script sits in middle as shown in image.

We will use JSON(JavaScript Object Notation) format. JSON is a lightweight text-based open standard designed for human-readable data interchange.
How json will be used in our application.
-When android application will execute, it will connect android device to PHP Script.
-PHP Script will fetch data from the database. It will encode it into json format and send it to the device.
-Now, android application will get these encoded data. It will parse the data and display it on android device.

Here is the implementation detail.
In MySQL create database Deal. In database create table CITY. This table consists of two columns. First is CITY_ID, which is auto_increment and primary_key and having data type INT. Second column is CITY_NAME, which has data type VARCHAR(20).

We want to retrieve city name from our table CITY that starts with A.
The PHP code will be very simple:
- connect to the database
- run an SQL query, with a WHERE block depending on data from POST/GET
values
- output it in JSON format

For example we will have this functionality in city.php:

<?php
mysql_connect("host","username","password");
mysql_select_db("Deal");
$sql=mysql_query("select * from CITY where CITY_NAME like 'A%'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>

In our Android application,
-use a HttpPost to get the data,
-convert response to string
-parse JSON data, and use it as you want

The whole code of retrieving data from server to our android application is shown as below.

package com.list;

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://10.0.2.2/city.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
int ct_id;
String ct_name;
try{
      jArray = new JSONArray(result);
      JSONObject json_data=null;
      for(int i=0;i<jArray.length();i++){
             json_data = jArray.getJSONObject(i);
             ct_id=json_data.getInt("CITY_ID");
             ct_name=json_data.getString("CITY_NAME");
         }
      }
      catch(JSONException e1){
    	  Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
      } catch (ParseException e1) {
			e1.printStackTrace();
	}
}
}
    }

Do not forget to insert following permission in AndroidManifest.xml.

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

Following are the links of other Post on Android.
Android: Upload image to Server
Android : ContextMenu & SubMenu
Android : Sliding Drawer
Android Countdown Timer
Getting started with Android Map View: Displaying a location by Marker
Simple Progress Bar in Android using Thread
Android listview with image and text

183 comments

  1. Chris

    This is awesome. You are a genius! Thanks for the tutorial!

    Could you quickly show me how to do the opposite and post information (it can be hard-coded) to the database please? Just e-mail me!

    1. bhargav

      This is a good question.
      Well, we can also insert data from mobile device to our database. For that we need to change some code of PHP script. Suppose that we want to insert record in our table CITY. Following is the insertion query.

      insert into CITY (CITY_NAME)values(‘ “.$_REQUEST['c_name'].” ‘)

      like that we can also modify existing record of table as shown below.

      update CITY set CITY_NAME=’ “.$_REQUEST['c_name'].” ‘ where CITY_ID=22

      To complete the above task, we need to pass the data from mobile device to PHP Script, this can be done by inserting following java code in our activity file.

      ArrayList nameValuePairs = new ArrayList();
      nameValuePairs.add(new BasicNameValuePair(“c_name”,”New York”));

      I have submitted here whole code of php Script and .java file.

      1. Chris

        bhargav – Thank you so much! I have spent the last few days googling how to do post data to a mysql database via JSON, I didn’t find anything!. That is, until I found your blog (thankfully!). My scripts are working great and I have been jumping up and down.

        You have one of the most helpful/easy to understand blogs about Android i’ve seen on the web, definitely going to bookmark it! Thanks again!!!

        1. shadowSRB

          Chris could you send me all code? My code is gona crazy. I don’t know how to force to work.

      2. sreeram

        Hi bhargav,

        Please could you provide the complete source code, which is working absolutely fine….Am new to android….I want to setup this application in my local…please help on this

      3. ramalakshmi

        Hi!
        thanks for the tutorial.I follow the above code in my project which is similar to your code.but i failed.please make currections in this.please give me reply.
        my php file is

        output of this php file is

        [{"id":"3","Symbol":"Platinum","Bid":"1635","Ask":"1646"},{"id":"1","Symbol":"Gold","Bid":"1715","Ask":"1721"},{"id":"2","Symbol":"Silver","Bid":"33","Ask":"34"},{"id":"4","Symbol":"Crude","Bid":"100","Ask":"101"}]

        my android code is same as you write.i used the url as http://localhost:8000/rates.php
        i changed only the following code as

        try{
        jArray = new JSONArray(result);
        JSONObject json_data=null;
        for(int i=0;i<jArray.length();i++){
        json_data = jArray.getJSONObject(i);
        _id=json_data.getInt("id");
        _simbl=json_data.getString("Symbol");
        }
        }
        please help where i am wrong.please please help me. :sad:

  2. Marco Montes Neri

    hi!! thank you very much. there are errors in my code related to the “is” (InputStream) variable. Sorry , maybe this is very basic. but why could that be?

  3. ravi

    actually where we have to keep city.php file and where we have to write code
    The whole code of retrieving data from server to our android application is shown as below.

    1. bhargav

      As shown in the image of this blog, PHP script is at server side. So you need to install server. Make the database on Mysql. Run the city.php file. If it works, then implement the connection between android and MySQL. Make sure that while making connection your server is start.

      1. manas

        Hey, thanks for the nice tutorials.
        But,I’m a novice to these stuff, so not getting HOW to INSTALL SERVER??
        I mean, Do we have to do that stuff on some other machine & where to write php code actually (in XAMPP, or ny other tool)?

      2. swapnil

        i have installed server but my log shows connection to localhost refused

  4. Meriam

    Hi Marco, you should declare an inputStream before the httpPost::
    InputStream is = null;
    I think that will solve your problem ;-)

    1. Marco Montes Neri

      thank you Meriam, you are right, though there was a warning still , but it was fixed changing the version of java :smile:

  5. Mutinda

    i cant get any results but only android application error that i dont know what is the cause….
    “Application has failed unexpectadly ” ….

    My City.php file is in the xampp-> htdocs->Android Apps – - folder but when i include this as my httppost – - HttpPost httpPost = new HttpPost(“http://localhost/Android Apps/City.php”); also tried
    HttpPost httpPost = new HttpPost(“http://127.0.0.1/Android Apps/City.php”); but never works…

    I would appreciate if you help me on this.
    Thanks

    1. bhargav

      Use following line, it works,
      HttpPost httppost = new HttpPost(“http://10.0.2.2/Android Apps/City.php”);

      If you need to refer to your host computer’s localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer’s loopback interface. From the emulator’s perspective, localhost (127.0.0.1) refers to its own loopback interface.

      1. marinela

        Can you explain me how to acces my database, I have a mysql data on localhost, and when I run emulator it returns that it’s stoped working. How to connect al those things, mysql- android?
        thanks

  6. siddu

    how get image from my sql? in this case

    1. bhargav

      Best method to load image from server to android device is as following.
      Just insert the url of image into mysql. Now, in android application, according to criteria fetch the url of the image from mysql. Question is that how to load the image from url. For that following is a link of my blog that retrieves image from server.
      http://blog.sptechnolab.com/2011/03/04/android/android-load-image-from-url/

  7. TNcod

    How about taking picture via Android 2.2 device camera (like Galaxy Tab) and sending this with few extra info to mySQL.
    Like this: in Android a small UI with input boxes
    - Image title (user fill text)
    - Small description (user fill text)
    - another extra info (user fill text)
    Snapshot button for taking the picture (1 or up to 4)
    Thumbnail to show taken picture
    SEND -button

    When filling the text fields and picture taken, pressing SEND -button Android connects to server, downloads taken picture to server folder and makes data entry to mySQL (writing text fields to db with image name downloaded to folder).

    With this, user could have only this small UI open in Android device, and it could be used for making lot of data entries with additional text and images directly to mySQL with minimum clickings or going forward and backward between different UI’s.

    1. bhargav

      Ok, main question is that how to upload an image from android device to server. So that image can be stored at server side in specific folder. For that i have posted a tutorial and its link is here, http://blog.sptechnolab.com/2011/03/09/android/android-upload-image-to-server/

  8. hasnainkiani

    hi to all ,

    can any one help me out for making In Android application, in this context that is (client-server architecture) where can i write this code in my app and which libraries are used. for this android side?

  9. hasnainkiani

    hi chris can you give me the code for android side progrmming , i wanna develop the app for android that will login on the server which is remote server. but i faced some problems in my app
    1. how can i post data on server (which is based on php and mysql)
    2. how can i get the data from server
    3. how can i used the data in listview items

    can help me step by step tutorials or any thing else for my help ?

  10. George

    Hello bhargav your code is really useful for my first steps in android developing.I was wondering why the Log messages are not displayed in my screen? I m using them as you did above. Do you have any idea about that?? Is there any good tutorial about displaying these data in a ListView(Im not lazy just little confused)… Keep going great job ;-)

    1. bhargav

      Hi George, here is the link that contains whole java code to fetch data from server and to display these data in ListView.
      java.pdf

      1. day

        hello bhargav…the code isnt working…why ? when i run the code, my emulator show me the message that this program has stopped unexpectedly

        1. bhargav

          Hi, information you have given is very short. An Example that i have shown works perfectly. Reply me with the error message from LogCat.

          1. day

            hi again….finally it works….after i add the permission for accessing internet in androidmanifest…thank you very much bhargav…..i’m very new with android sorry if i ask too much :mrgreen:

          2. day

            hi again bhargav there is something that i still don’t understand in your code here it is

            BufferedReader reader = new BufferedReader(new InputStreamReader(is,”iso-8859-1″),8);

            can you explain this to me especially the “iso-8859-1″, can i change it to something other

  11. Ramji

    pls post the login form which verify user name and password in mysql database…

  12. vivek

    Hi sincere thanks to you … This article is very clear in conveying the information. keep it up

    1. Ishwari Shah

      Hii vivek,
      I am new learner,and even i want to retrieve mysql data using php and view it on android device.I tried to use same code as show above in this block but i am getting NullPointEception in logcat on line-
      JSONArray jArray = new JSONArray(result);
      so can you help me plz..

  13. Ishwari Shah

    Hiii,I tried using your code but i am getting NullPointException on line-JSONArray jArray = new JSONArray(result);..(its from ur code only.)..Can you help me and explain it as i am new to android and willing to read mysql database using php..I really hope you reply as soon as possible.

    1. bhargav

      In php script use such SQL query that fetches some values from database. You are getting error because result variable is still null.

      1. Ishwari Shah

        Thanks for your quick reply,But my php page is retrieving data from mysql server when i had checked on browser.But when i am calling in the calss its giving exception.please can you guide me please.. Waiting for your quick reply..

        1. bhargav

          I have checked your code, there is not any error. First time you were getting error, because android did not get data from the server or might be you had set wrong url in java code.

          1. Ishwari Shah

            hey thanks for your reply…
            and now my code is displaying a data on emulator in array form as jArray is holding data..But
            now i want to display data in list format..
            As i am not under standing how to view it.So can u help me with some code.
            Thanks in advance..
            Waiting for quick reply..

          2. bhargav

            Here is a link of blog that populates image and text into listView, http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/. Using this tutorial you can implement list with more then one parameter.

  14. ishwari Shah

    Hii Friends,
    I have done successfully to view data from mysql through php..Now my problem is to pass the input variable which is entered in text view and pass it to php page and fire query according to entered variable and display result on android emulator..
    Please can to help me out with my problem as early as possible..

  15. Purav

    i want to pass the variable with the call of php page and using that variable select query is need to fire.So please can any one provide me with accurate code..eagerly waiting for reply

  16. bumdeal2

    Great article,

    Clear,precise and to the point. Keep it up :-) and I was looking at a link you previously recommended further up the page( http://blog.sptechnolab.com/wp-content/uploads/2011/02/java1.pdf) just out of interest, how would allow a user to search the database.

    Thanks you.

  17. VIVEK PRASAD

    Iam facing this error while inserrting data in mysql through php script in android
    JSON failed ; Value<?phpmysqlconnect("localhost" of type java.lang.String cannot be converted to JSONObject

    plz help

  18. rika

    hi….

    im very new in android, i hope u can help me

    i use eclipse, where should i code php file, in same project with java file or different?

  19. rika

    hi..

    i got error ‘source not found’ .

    I put php file on htdocs folder of the server. Hope u can help me :(

    Thx

    1. bhargav

      Suppose, file name of php script is City.php, to connect this file from android, use following url to post or get the data.
      http://10.0.2.2/City.php

      1. rika

        my php file and http already same. my php file is hotelphp.php, and the http “HttpPost httppost = new HttpPost(“http://10.0.0.2/hotelphp.php”);” , but still got error :(

      2. rika

        hi..

        the error ‘source not found’ has solved but i got these messages:

        ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2663
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679
        ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125
        ActivityThread$H.handleMessage(Message) line: 2033
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99
        Looper.loop() line: 123
        ActivityThread.main(String[]) line: 4627
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
        Method.invoke(Object, Object…) line: 521
        ZygoteInit$MethodAndArgsCaller.run() line: 868
        ZygoteInit.main(String[]) line: 626
        NativeStart.main(String[]) line: not available [native method]

  20. VIVEK PRASAD

    But how can i make connection when iam using andriod mobile, i have made a login program in android the output is coming on my galaxy fit mobile but after entering username & password it gives the error \ java.net.SocketException . The operation is time out \ plz tell me any solution for this early
    .Thanks

  21. VIVEK PRASAD

    when iam deploying my apps on samsung galaxy fit for user login it will give error message “java.net.UnknownHostException”
    any help greatly appreciated

  22. Mike

    Thanks for the tutorial, it seems really helpful, but I am having errors in Eclipse. For some reason, in this line of code Log.e(“log_tag”, “Error converting result “+e.toString());
    the .e is underlined saying that the method e(String, String) is undefined for the type Log.
    Any idea what that might be? Thank you in advance

    1. bhargav

      An error is occurring because you are importing wrong package, import org.apache.commons.logging.Log;. Instead of that use following line in your code, import android.util.Log;

  23. Rohit

    hiiiiii,
    this code is working properly.But now i want to store data in mysql by android by the insert query.How it will work.

    Please explain any example or send it to my mail..
    (Thanks in advance)

  24. lokistro

    what is result . showing …………………………………..

    Please explain any example or send it to my mail.. or source code

  25. Paul

    Very good post…I was able to get up and running with your tutorial in a very short time. One thing that other users might stumble upon (I did) is the required tag in the manifest file:

    -Paul

  26. Axel E. Christensen

    hi
    Thanks for a fine tutorial.
    I do have problems getting it to work. When I create it with Eclipse I get this error message in the Emulator: “The application test (process core.test) has stopped unexpectedly.Please try again. The app did compile without any errors.
    When I try to install it on my Android devide (Galaxy Tab) I get : “Parse Error. There is a problem parsing the package”
    I have used the code in your example with very few change.
    Can you advise me on how to proceeed ?
    Thansk

    Axel

    1. bhargav

      Reply with the logcat entries and column names of the table because column names are used for parsing the json data.

  27. Maanasa

    Hi,
    I was trying out this piece of code and somehow it just doesn’t work fine.
    I try to access a db on a different machine and my php file is on the same.
    So i use the URL of the machine with the entire socket address http://ipaddr:port/connect.php
    I define some dummy namevaluepairs and try running the code. It fails at “HttpEntity entity = response.getEntity();the http ”

    I have made sure i can access the file from the browser.
    The network monitor also does not show any activity when run through the app whereas it shows the access to the server when i open it through the browser.

    What could i be doing wrong here?

    Thanks,
    Maanasa

    1. bhargav

      Hi,
      You are saying that php file is on same machine. Use following line in java file to connect android to php.
      HttpPost httppost = new HttpPost(“http://10.0.2.2/connect.php”);

      Now, database is on different machine. Following function is used in php script to connect php and mysql.
      mysql_connect(“host”,”username”,”password”);
      where, host=ip address of remote machine.
      username and password are used to aceess the database.

      1. maanasa

        Hi Bhargav,
        I initially had the php script and the db on a different machine. However i now tried with all the 3 – db, php script and app code on the same machine. I still get the same exception at the same point. On printing the exception in the catch block, this is what it shows :
        05-01 14:40:35.753: ERROR/log_tag(275): Error in http connectionjava.net.SocketException: Permission denied

        Am not sure what permission is required at what stage. I have given the
        host – name of my computer,
        username – root,
        password – the root password
        in the php script.

        1. bhargav

          Add following permission in AndroidManifest.xml file of Android project.
          <uses-permission android:name=”android.permission.INTERNET”></uses-permission>

  28. lokistro

    explain to step by step
    This program
    not working
    Please help me people

  29. dude

    Below are my errors:

    nameValuePairs cannot be resolved to a variable
    jArray cannot be resolved to a variable

    How do I resolve these errors?

    1. bhargav

      I have updated my code, so you will not get error.

      1. dude

        Thanks for the code update.

        I’m still getting the application has stopped unexpectedly error. How do I go about troubleshooting this error? Our Mysql server is on a different machine than our Android code. Would that matter?

        1. bhargav

          Yes, specify the ip address of the remote machine in php script instead of localhost.

  30. Tamir

    Hi all,

    i got same error like:

    application has stopped unexpectedly error.

    Android code and PHP files are located same localhost and city.php working fine.

    city.php result is: [{"city_id":"1","city_name":"Ankara"},{"city_id":"2","city_name":"Aav"},{"city_id":"3","city_name":"aaa"},{"city_id":"4","city_name":"aadfd fsdfsf"},{"city_id":"6","city_name":"asdasdsdasd"}]

    What sould i check?

  31. Ong Wen jian

    Hi ..

    I able to compile the source code using eclipse.
    However, once i download to my android device, it says the process ended unexpectedly ..

    May I know how to debug this error ??

    regards
    wen jian

    1. bhargav

      I think you are trying to connect localhost from android device. You are getting en error because you have not setup a network connection between them. So, make connection and use a url of php that you want to access in android device.

  32. Richm

    Hi, thanks for the example BUT (and this may sound obvious) when run nothing is displayed on screen. So do I do something with the two variable ct_id and ct_name ??

    I tried just inserting one field into an array but a blank screen was displayed still.
    I tried to put them into an array and bind it to a screen listview widget – failed on incompatible types.

    it is probably very simple but as a new Androidee I am stumped.

    Richard

  33. Richard

    Hi Bhargav,

    your examples were excellent but I still don’t understand why there are no records being displayed on the layout xml. Everything runs fine, the php file script is good when tested outside of Android BUT when called from the example code all I get is the toast message “no cities found”. My sql DB is fine also. it appears that two vars ct_id and ct_name are never used……

    Any thoughts/ pointers please ? If I can get the records displayed I will be one happy bunny!
    Richard

    1. Shabana.G

      Hi Richard,

      I’m having that same problem and i have no idea what’s the cause of it…

  34. denny

    hi bhargav i’ve succeed to connect and display . now i’m trying to make a project that can update my data in mysql database, the problem is when i run the application it works and connect but there’s no update in my database….can you tell me what i supposed to do?

    1. bhargav

      Actually, from this information i can not figure out the exact problem. so send me the code, so that i can correct it.

  35. Wil Smith

    Hi,

    I am wrecking my brains over this. I can not get the application to run. I am running it from my device and not the emulator. I am also using a web based server from host gator. I have my DB on the server and the php script on the server. I created a folder under my domain name to house the php script, where should the db be put. Please help me as I am almost there I think.

    1. bhargav

      Hi,
      First, get the actual url of the php script. Use this url in java code to make connection between android and php script. Now, in php script change function as shown below.
      mysql_connect(“host”,”username”,”password”);
      where, host=ip address of remote machine.
      username and password are used to access database.

  36. krilov

    hi there, 1st of all tnx 4 the tut and your time.
    Since days i’m trying to run a really similar application but checking and rechecking the code and googling 4 any solution, it still doesn’t work properly.
    Basicly, once i run the AVD emulator, i just see the url “http://10.0.2.2/connect.php” , in spite of having the query result.
    Now before running it on android, i tested the php file and the query ( and so MYSQL connection & Co too) alone, and it worked rightly.

    I’ve readen somewhere that i could try to specify my ip 192.168.1.4 in spite of the 10.0.2.2 but i still keep seing the url string on the Emulator.
    i’ve added the permissions in the manifest.xml file as pointed here, i’ve deleted the minSDK required line too…still the same result.
    i’m using eclipse-java-helios-SR2-win32 ( = 3.6 right?)
    The AVD used for that project is the 2.2
    I tried to delete the current avd and then creating a new one…as someone told me..but it still didn’t work for me.
    LOL right 5 minutes ago i tried to implement it on an online site created onfly that got Mysql ofc…..nothing…still the same problem: i only see the url: http://www.ablablabl….

    1. bhargav

      If php script executes on same development computer, then use “10.0.2.2″. If it is on different computer then get the url of that php file, and use it in place of “10.0.2.2″.

      1. krilov

        as said…i’ve used that special ip 10.0.2.2 just like here in the example….HttpPost(“http://10.0.2.2/city.php”)
        While on my php file i used mysql_connect(“127.0.0.1″,”user”,”password”);

        But again, the emulator does show only http://10.0.2.2/city.php as output without displaying the query result.
        So i guess there must be something else wrong but dunno what ;/

  37. rakib

    how can i send integer or floating number variables to server from android client?

    1. bhargav

      Convert integer or floating values to string and send it to server.

  38. rakib

    can i both send and receive data through one php script?i m really having touble doing so..i can receive data but not being able to send at the same time..it would be really helpful if u can give me some idea..here’s the code for php script :

    here’s the code for android:
    nameValuePairs.add(new BasicNameValuePair(“lat”, slat));
    nameValuePairs.add(new BasicNameValuePair(“lon”, slon));
    try{
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost =new HttpPost(“http://10.0.2.2/android/server.php”);
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));//???
    HttpResponse response = httpClient.execute(httpPost);
    HttpEntity entity = response.getEntity();
    is=entity.getContent();}

    1. rakib

      and here’s the code for php script :

      mysql_connect(“localhost”,”root”,”");
      mysql_select_db(“android”);
      $sql=”INSERT INTO gps (lat, lon, stat)
      VALUES
      (‘”.$_REQUEST['lat'].”‘,’”.$_REQUEST['lon'].”‘,’”.$_REQUEST['stat'].”‘)”;

      $sql=mysql_query(“select * from gps”);
      while($row=mysql_fetch_assoc($sql))
      $output[]=$row;
      print(json_encode($output));
      mysql_close();

      1. bhargav

        Problem is that from android you are sending value of two key words, “lat” and “lon”. And at php script you are trying to fetch value of three key words, “lat”, “lon”, “stat”.

    2. bhargav

      It would be better if you create different php script for retrieving and sending data to server.

  39. Ishwari Shah

    Hii,
    i am trying to send parameters with the address of php page to fire query with that parameter.
    code:
    String service,position;
    ip_var=”"+ urlpath+”phppage1.php”;
    final String KEY_121 =ip_var+”?&position=” + position+”&”+”?&item=” +service;
    ———————————————–
    But its giving me following error in Logcat:
    Error parsing data org.json.JSONException: Value C0831 of type java.lang.String cannot be converted to JSONArray.

    where service=C0831.
    So can tell me what changes to make in code??

  40. MeNotYou

    Great tutorial man! Really helped me a lot!

    I was wondering if you could do a tutorial on something similar:
    I don’t need to live connect with a database, because that takes too much time when checking records.
    Instead, I want to download the remote mysql table to the phone’s database so I can check data instantly.
    I searched the www, but could’nt find ANY useful tutorial… would be pretty cool if you could help me with this problem!

    Keep up the good work!

    1. John McDonalds

      +1 for this… I could really really use that too and cant find anything on the internet

    2. MissY

      Yeah, me too! Does anyone know how to do this, or where I can find a tutorial?
      Cant find anything on the web,altough i think it’s something lots of people want to know and could use!
      Would REALLY appreciate it!

  41. Szolt

    Bhargav, thanks very much for this clear example. However my code fails somewhere – I cannot identify where. I get a Force Close error “the application has stopped unexpectedly……” I cannot attach the logcat since it stopped working suddenly for some reason and displays nothing.

    Thanks very much, any help will be appreciated.

    Here is my code:

    //Manifest file

    //Android

    package com.example.android;
    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 PHPQuery 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 nameValuePairs = new ArrayList();
    //http post
    try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(“http://10.0.2.2/mysql_select_city.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
    int ct_id;
    String ct_name;
    try{
    jArray = new JSONArray(result);
    JSONObject json_data=null;
    for(int i=0;i<jArray.length();i++){
    json_data = jArray.getJSONObject(i);
    ct_id=json_data.getInt("CITY_ID");
    ct_name=json_data.getString("CITY_NAME");
    }
    }
    catch(JSONException e1){
    Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
    } catch (ParseException e1) {
    e1.printStackTrace();
    }
    }
    }

    1. bhargav

      Ok. i tried your code, it works perfectly. Make sure following points.
      -Insert INTERNET permission in AndroidManifest.xml file.
      -php script is working properly or not.
      -Use following line in your code in place of old one,
      public class PHPQuery extends Activity {

      1. Szolt

        Bhargav I have done all those. I put my permissions tag below the application tag in the manifest. My script works ok. Maybe it is my name value pairs that are going wrong somewhere ?

        1. bhargav

          nameValuePairs is used to send data from android to php. We are trying to fetch data from php to android. So, there is not a problem of nameValuePairs. Reply me with the logcat, so that i can help you.

          1. Szolt

            Hi Bhargav, this is my logcat. The log when I ran the app was too big and does not stop getting output once I run, so I put a section that has the errors in it. I tried using httpurlconnection and that works, but http post does not run my php file. How would I pass a parameter to httpurlconnection ?

            Thanks for your help.

            06-19 18:30:12.362: DEBUG/lights(1417): set_light_buttons_func: on=16777215 brightness=255
            06-19 18:30:12.362: DEBUG/PowerManagerService(1417): setPenMenuButtonLed: 4
            06-19 18:30:12.362: INFO/WindowManager(1417): Setting rotation to 0, animFlags=1
            06-19 18:30:12.362: DEBUG/PowerManagerService(1417): button light setOrientation:0
            06-19 18:30:12.362: DEBUG/PowerManagerService(1417): setPenMenuButtonLed: 4
            06-19 18:30:12.382: INFO/ActivityManager(1417): Config changed: { scale=1.0 imsi=302/610 loc=en_CA touch=3 keys=1/1/2 nav=1/1 orien=1 layout=34 uiMode=17 seq=19 skin=default}
            06-19 18:30:12.401: INFO/laputa_lb(2154): [LbContentProvider] >> onConfigurationChanged
            06-19 18:30:12.401: INFO/laputa_lb(2154): [updateLocale] locale is the same
            06-19 18:30:12.401: INFO/laputa_lb(2154): [LbContentProvider] update locale res: false
            06-19 18:30:12.401: INFO/laputa_lb(2154): [LbContentProvider] update locale ticks: 6
            06-19 18:30:12.401: INFO/laputa_lb(2154): [LbContentProvider] <Intent { act=com.htc.launcher.action.ACTION_ITEM_ADDED cmp=com.htc.android.mail/.AppMonitorReceiver (has extras) },component=com.htc.android.mail/.MailListTab
            06-19 18:30:12.922: DEBUG/AppMonitorReceiver(2120): 06021143 update mail shortcut>
            06-19 18:30:12.942: DEBUG/MessagingShortcutReceiver(1813): keep hiding shortcut bubble
            06-19 18:30:13.082: DEBUG/dalvikvm(1417): GC_FOR_MALLOC freed 42010 objects / 1985544 bytes in 92ms
            06-19 18:30:13.112: DEBUG/SurfaceFlinger(1417): Layer::setBuffers(this=0x9864e8), pid=1417, w=800, h=442
            06-19 18:30:13.112: DEBUG/SurfaceFlinger(1417): Layer::setBuffers(this=0x9864e8), pid=1417, w=800, h=442
            06-19 18:30:13.182: ERROR/lights(1417): write ok string=1,len=1
            06-19 18:30:13.182: ERROR/lights(1417): write ok string=0,len=1
            06-19 18:30:13.182: ERROR/lights(1417): write ok string=0 0,len=3
            06-19 18:30:13.182: ERROR/lights(1417): write ok string=0,len=1
            06-19 18:30:13.182: ERROR/lights(1417): write ok string=0,len=1
            06-19 18:30:13.182: ERROR/lights(1417): write ok string=0 0,len=3
            06-19 18:30:13.182: DEBUG/SurfaceFlinger(1417): Layer::requestBuffer(this=0x52b630), index=0, pid=1417, w=480, h=38 success
            06-19 18:30:13.182: VERBOSE/NotificationService(1417): Charging…
            06-19 18:30:13.202: DEBUG/SurfaceFlinger(1417): Layer::requestBuffer(this=0x9864e8), index=0, pid=1417, w=480, h=762 success
            06-19 18:30:13.262: DEBUG/InputManagerService(1417): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@47db8b50
            06-19 18:30:13.452: DEBUG/MessagingShortcut(1813): updateMsgShortcut, msg count> 0
            06-19 18:30:13.452: DEBUG/MessagingShortcut(1813): mPresentUnreadCount: 0
            06-19 18:30:13.462: DEBUG/MessagingShortcut(1813): setMsgShortcutDrawable> 0
            06-19 18:30:14.891: DEBUG/dalvikvm(1417): GC_EXPLICIT freed 12200 objects / 551800 bytes in 114ms
            06-19 18:30:16.211: DEBUG/ContactMessageStore(1528): onChange() >>

          2. bhargav

            Ok, you forgot to tell me that you were trying to connect mysql from htc device. See, the given code works on emulator not on device. From htc device, you can not connect to localhost.

  42. krilov

    bahh..it doesn’t work as it should. Even if i change the datas to have as output (4example just name field) it keeps showing all infos. 0_o

    Let me show you ma noobz example…( well not mine since i took it from an other example..but well it’s just like yours)
    —————-
    Here is the java file : whitehat.java
    —————-
    package com.connector;

    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.apache.http.message.BasicNameValuePair;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;

    import android.app.Activity;

    import android.os.Bundle;
    import android.util.Log;
    import android.widget.LinearLayout;
    import android.widget.TextView;

    public class whitehat extends Activity {
    /** Called when the activity is first created. */

    TextView txt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Create a crude view – this should really be set via the layout resources
    // but since its an example saves declaring them in the XML.
    LinearLayout rootLayout = new LinearLayout(getApplicationContext());
    txt = new TextView(getApplicationContext());
    rootLayout.addView(txt);
    setContentView(rootLayout);

    // Set the text and call the connect function.
    txt.setText(“Connecting…”);
    //call the method to run the data retreival
    txt.setText(getServerData(KEY_121));

    }
    public static final String KEY_121 = “http://10.0.2.2/dbAndroid/getAllPeopleBornAfter.php”;

    private String getServerData(String returnString) {

    InputStream is = null;

    String result = “”;
    //the year data to send
    ArrayList nameValuePairs = new ArrayList();
    nameValuePairs.add(new BasicNameValuePair(“year”,”1970″));

    //http post
    try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(KEY_121);
    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);
    StringBuilder sb = new StringBuilder();
    String line = null;
    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());
    }
    //parse json data

    try{
    JSONArray jArray = new JSONArray(result);
    for(int i=0;i<jArray.length();i++){
    JSONObject json_data = jArray.getJSONObject(i);

    Log.i("log_tag","id: "+json_data.getInt("id")+
    ", name: "+json_data.getString("name")+
    ", sex: "+json_data.getInt("sex") +
    ", birthyear: "+json_data.getInt("birthyear")
    );

    //Get an output to the screen
    returnString += "\n\t" + jArray.getJSONObject(i);
    }
    }catch(JSONException e){
    Log.e("log_tag", "Error parsing data "+e.toString());
    }
    return returnString;
    }
    }

    —————-
    Here is the manifest
    —————-

    —————-
    Here is the php file :
    —————-
    ‘”.$_REQUEST['year'].”‘”)
    or die (” Errore nella query”);

    while($e=mysql_fetch_assoc($q))

    $output[]=$e;

    print(json_encode($output));

    mysql_close();
    ?>

    ———————————
    Here is the sql used for creating the table inside the DB called peopledata
    ———————————
    CREATE TABLE people (

    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,

    name VARCHAR( 100 ) NOT NULL ,

    sex BOOL NOT NULL DEFAULT ’1′,

    birthyear INT NOT NULL

    )

    —————–
    Doh, sorry for stressing you so much…i know u hate me but would be fking cool if u can try to run it and check where the error is…cuz it seems i’m blind.

    1. krilov

      Jesus, i forgot the manifest….lol this thing is making me crazy..

      —-
      manifest
      —-

  43. kenny

    can you provide us the database table? ;-)

  44. yashpal

    Im getting force close error in android. I ve saved my php file here:-C:wampwwwIPL.My file name is all.php. in my code i ve mentioned:-HttpPost(\http://10.0.2.2/www directory/ipl/all.php\). Im also getting warnings that my ct_id,ct_name is never read. M struggling with tis since a long tym, so i wud greatly appreciate any help. thanku

    1. bhargav

      Try to use following url to access php script from android,
      “http://10.0.2.2/IPL/all.php”
      Also make sure that server is on.

  45. Szolt

    Hi Bhargav, sorry I did not mention the htc device. I have been trying from emulator to localhost as well which did not work, as well as to a remote dbase from emulator and then from the HTC device. None work through http Client but I can get it the remote and localhost call to work by using HttpUrlConnection.

    I use a php script on the remote device that specifies the localhost and from android I call the remote ip with port 8080 like this. ”http://’remote ip’:8080/mysqlcityinsert.php”

    The script works with httpUrlConnection by the way. Now I am trying to pass parameters through httpUrlConnection since my httpClient somehow does not work. The code is exactly the same as you have posted.

    Would appreciate if you have any answer why it is failing. Thanks for your help so far.

  46. Raj

    Hello ,

    Your efforts and commendable and it is a very good project

    I am very new to Android programming . I have just made a simple Hello Android project till now..As a part of an assignment giving to me by me college I need to connect remote mySql database from android phone..Ur code fits my requirement but i didnt understand the follwing things
    1) where to write the php file ( is it in notepad? ) and where to save it ? any specific s/w to be used ..i have wamp server installed on my pc , so how to use it ?

    2) what changes are to be made to the main.xml , AndroidManifest.xml , strings.xml etc

  47. Raj

    this is my log cat:

    06-21 13:14:16.476: INFO/ActivityThread(205): Pub downloads: com.android.providers.downloads.DownloadProvider
    06-21 13:14:16.996: INFO/ActivityThread(205): Pub drm: com.android.providers.drm.DrmProvider
    06-21 13:14:17.257: DEBUG/dalvikvm(32): GC_EXPLICIT freed 10K, 53% free 2538K/5379K, external 716K/1038K, paused 942ms
    06-21 13:14:17.617: DEBUG/dalvikvm(32): GC_EXPLICIT freed <1K, 53% free 2538K/5379K, external 716K/1038K, paused 364ms
    06-21 13:14:18.147: DEBUG/dalvikvm(32): GC_EXPLICIT freed 0)
    06-21 13:14:20.297: WARN/dalvikvm(42): threadid=4: spin on suspend resolved in 1080 msec
    06-21 13:14:20.297: DEBUG/dalvikvm(42): Restored policy of 193 to 0
    06-21 13:14:20.297: DEBUG/dalvikvm(42): Restored priority on 193 to 10
    06-21 13:14:20.817: INFO/Process(42): Sending signal. PID: 115 SIG: 3
    06-21 13:14:20.817: INFO/dalvikvm(115): threadid=4: reacting to signal 3
    06-21 13:14:20.907: INFO/dalvikvm(42): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:20.907: INFO/Process(42): Sending signal. PID: 117 SIG: 3
    06-21 13:14:20.907: INFO/dalvikvm(117): threadid=4: reacting to signal 3
    06-21 13:14:21.038: INFO/dalvikvm(117): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:21.208: INFO/dalvikvm(115): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:21.247: INFO/ActivityManager(42): Process com.android.settings (pid 163) has died.
    06-21 13:14:21.247: INFO/ActivityManager(42): Low Memory: No more background processes.
    06-21 13:14:23.207: INFO/TelephonyRegistry(42): notifyServiceState: 0 home Android Android 310260 UMTS CSS not supported 0 0RoamInd: 0DefRoamInd: 0EmergOnly: false
    06-21 13:14:23.287: INFO/TelephonyRegistry(42): notifyDataConnection: state=0 isDataConnectivityPossible=false reason=null interfaceName=null networkType=3
    06-21 13:14:24.537: DEBUG/MccTable(115): updateMccMncConfiguration: mcc=310, mnc=260
    06-21 13:14:24.537: DEBUG/MccTable(115): locale set to en_us
    06-21 13:14:24.537: DEBUG/MccTable(115): WIFI_NUM_ALLOWED_CHANNELS set to 11
    06-21 13:14:24.577: INFO/WifiService(42): WifiService trying to setNumAllowed to 11 with persist set to true
    06-21 13:14:25.607: WARN/dalvikvm(42): threadid=10: spin on suspend #1 threadid=39 (pcf=0)
    06-21 13:14:25.607: DEBUG/dalvikvm(42): Temporarily moving tid 193 to fg (was 0)
    06-21 13:14:25.607: DEBUG/dalvikvm(42): Temporarily raised priority on tid 193 (10 -> 0)
    06-21 13:14:25.627: WARN/dalvikvm(42): threadid=10: spin on suspend resolved in 1022 msec
    06-21 13:14:25.627: DEBUG/dalvikvm(42): Restored policy of 193 to 0
    06-21 13:14:25.627: DEBUG/dalvikvm(42): Restored priority on 193 to 10
    06-21 13:14:26.127: DEBUG/dalvikvm(42): GC_EXPLICIT freed 1081K, 47% free 4282K/8007K, external 3511K/4711K, paused 493ms
    06-21 13:14:26.297: INFO/ActivityManager(42): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=4}
    06-21 13:14:26.547: INFO/TelephonyRegistry(42): notifyMessageWaitingChanged: false
    06-21 13:14:26.587: INFO/TelephonyRegistry(42): notifyCallForwardingChanged: false
    06-21 13:14:26.687: INFO/ActivityThread(231): Pub com.android.mms.SuggestionsProvider: com.android.mms.SuggestionsProvider
    06-21 13:14:28.267: DEBUG/TelephonyProvider(115): Setting numeric ’310260′ to be the current operator
    06-21 13:14:28.297: INFO/Process(42): Sending signal. PID: 125 SIG: 3
    06-21 13:14:28.297: INFO/dalvikvm(125): threadid=4: reacting to signal 3
    06-21 13:14:28.437: INFO/TelephonyRegistry(42): notifyDataConnection: state=1 isDataConnectivityPossible=true reason=simLoaded interfaceName=null networkType=3
    06-21 13:14:28.487: INFO/TelephonyRegistry(42): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=simLoaded interfaceName=/dev/omap_csmi_tty1 networkType=3
    06-21 13:14:28.628: INFO/dalvikvm(125): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:28.747: DEBUG/dalvikvm(42): GREF has increased to 301
    06-21 13:14:29.088: ERROR/ActivityManager(42): Load: 8.0 / 2.23 / 0.76
    06-21 13:14:29.088: ERROR/ActivityManager(42): CPU usage from 0ms to 10157ms later:
    06-21 13:14:29.088: ERROR/ActivityManager(42): 28% 42/system_server: 16% user + 11% kernel / faults: 429 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 15% 125/zygote: 8.5% user + 7.3% kernel / faults: 774 minor 2 major
    06-21 13:14:29.088: ERROR/ActivityManager(42): 15% 115/zygote: 7.6% user + 7.4% kernel / faults: 417 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 13% 231/zygote: 5.7% user + 8% kernel / faults: 3327 minor 6 major
    06-21 13:14:29.088: ERROR/ActivityManager(42): 8.3% 71/bootanimation: 5.9% user + 2.3% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 7.2% 205/android.process.media: 1.7% user + 5.5% kernel / faults: 201 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 6.2% 227/zygote: 2.6% user + 3.6% kernel / faults: 1868 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 1.1% 117/zygote: 0.7% user + 0.3% kernel / faults: 24 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.8% 31/rild: 0.3% user + 0.5% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.5% 37/qemud: 0% user + 0.5% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.3% 110/zygote: 0.2% user + 0% kernel / faults: 11 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.4% 172/android.process.acore: 0.3% user + 0.1% kernel / faults: 20 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0% 27/servicemanager: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 100% TOTAL: 50% user + 49% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): CPU usage from 7836ms to 9345ms later:
    06-21 13:14:29.088: ERROR/ActivityManager(42): 31% 42/system_server: 14% user + 16% kernel / faults: 50 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 15% 73/ActivityManager: 5% user + 10% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 9.4% 57/SurfaceFlinger: 6.5% user + 2.8% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 1.4% 51/Compiler: 0.7% user + 0.7% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 42/system_server: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 54/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 56/Binder Thread #: 0% user + 0.7% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 156/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 169/Binder Thread #: 0% user + 0.7% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 170/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 185/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 193/Thread-51: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 220/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 221/Binder Thread #: 0% user + 0.7% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 223/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 27% 115/com.android.phone: 17% user + 10% kernel / faults: 253 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 16% 115/m.android.phone: 8.6% user + 7.8% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 7.8% 155/Binder Thread #: 6.2% user + 1.5% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 153/Binder Thread #: 0% user + 0.7% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.7% 154/Binder Thread #: 0.7% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): +0% 256/Binder Thread #: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): +0% 257/Binder Thread #: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 15% 125/com.android.launcher: 5.6% user + 9.6% kernel / faults: 118 minor
    06-21 13:14:29.088: ERROR/ActivityManager(42): 9.6% 125/ndroid.launcher: 6.4% user + 3.2% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 6.4% 128/HeapWorker: 0.8% user + 5.6% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 16% 231/com.android.mms: 9.4% user + 7.5% kernel / faults: 208 minor 1 major
    06-21 13:14:29.088: ERROR/ActivityManager(42): 11% 231/com.android.mms: 6.6% user + 4.7% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): +0% 252/Thread-10: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): +0% 253/Thread-11: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): +0% 254/Thread-12: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): +0% 255/Thread-13: 0% user + 0% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 6.7% 71/bootanimation: 3.7% user + 2.9% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 8.2% 75/BootAnimation: 5.2% user + 2.9% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 0.6% 31/rild: 0% user + 0.6% kernel
    06-21 13:14:29.088: ERROR/ActivityManager(42): 100% TOTAL: 48% user + 51% kernel
    06-21 13:14:29.127: INFO/Process(42): Sending signal. PID: 205 SIG: 9
    06-21 13:14:29.577: WARN/ActivityManager(42): Timeout of broadcast BroadcastRecord{406b11d8 android.intent.action.BOOT_COMPLETED} – receiver=android.os.BinderProxy@406bb248, started 13240ms ago
    06-21 13:14:29.577: WARN/ActivityManager(42): Receiver during timeout: ResolveInfo{406471e0 com.android.mms.transaction.MmsSystemEventReceiver p=0 o=0 m=0×108000}
    06-21 13:14:29.857: INFO/Process(42): Sending signal. PID: 231 SIG: 3
    06-21 13:14:29.857: INFO/dalvikvm(231): threadid=4: reacting to signal 3
    06-21 13:14:30.087: INFO/Process(42): Sending signal. PID: 42 SIG: 3
    06-21 13:14:30.087: INFO/dalvikvm(42): threadid=4: reacting to signal 3
    06-21 13:14:30.207: INFO/dalvikvm(231): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:30.297: DEBUG/dalvikvm(231): GC_CONCURRENT freed 478K, 54% free 2716K/5831K, external 716K/1038K, paused 9ms+13ms
    06-21 13:14:30.558: INFO/Process(42): Sending signal. PID: 115 SIG: 3
    06-21 13:14:30.558: INFO/dalvikvm(115): threadid=4: reacting to signal 3
    06-21 13:14:30.627: INFO/dalvikvm(42): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:30.637: INFO/Process(42): Sending signal. PID: 117 SIG: 3
    06-21 13:14:30.637: INFO/dalvikvm(117): threadid=4: reacting to signal 3
    06-21 13:14:30.657: INFO/ActivityManager(42): Start proc com.android.deskclock for broadcast com.android.deskclock/.AlarmInitReceiver: pid=261 uid=10019 gids={}
    06-21 13:14:30.746: INFO/dalvikvm(117): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:30.996: INFO/dalvikvm(115): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:31.808: DEBUG/dalvikvm(125): GC_EXTERNAL_ALLOC freed 65K, 50% free 2847K/5639K, external 3206K/3516K, paused 378ms
    06-21 13:14:33.456: WARN/WindowManager(42): App freeze timeout expired.
    06-21 13:14:33.456: WARN/WindowManager(42): Force clearing freeze: AppWindowToken{40690a18 token=HistoryRecord{4058c9d0 com.android.launcher/com.android.launcher2.Launcher}}
    06-21 13:14:34.606: DEBUG/dalvikvm(125): GC_EXTERNAL_ALLOC freed 27K, 50% free 2865K/5639K, external 4420K/4437K, paused 430ms
    06-21 13:14:34.876: INFO/ActivityThread(261): Pub com.android.deskclock: com.android.deskclock.AlarmProvider
    06-21 13:14:35.756: DEBUG/dalvikvm(42): GC_EXPLICIT freed 1100K, 47% free 4305K/8071K, external 3511K/4711K, paused 520ms
    06-21 13:14:36.026: DEBUG/dalvikvm(42): GC_EXPLICIT freed 3K, 47% free 4302K/8071K, external 3511K/4711K, paused 213ms
    06-21 13:14:36.656: DEBUG/Tethering(42): MasterInitialState.processMessage what=3
    06-21 13:14:36.916: INFO/SurfaceFlinger(42): Boot is finished (69851 ms)
    06-21 13:14:36.986: INFO/ARMAssembler(42): generated scanline__00000177:03010104_00000002_00000000 [ 44 ipp] (66 ins) at [0x43d6f290:0x43d6f398] in 1355950 ns
    06-21 13:14:37.006: INFO/ARMAssembler(42): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x43d6f3a0:0x43d6f51c] in 1425242 ns
    06-21 13:14:37.386: INFO/Process(42): Sending signal. PID: 125 SIG: 3
    06-21 13:14:37.386: INFO/dalvikvm(125): threadid=4: reacting to signal 3
    06-21 13:14:37.396: DEBUG/dalvikvm(125): GC_EXPLICIT freed 56K, 50% free 2837K/5639K, external 4943K/5574K, paused 442ms
    06-21 13:14:37.476: INFO/dalvikvm(125): Wrote stack traces to ‘/data/anr/traces.txt’
    06-21 13:14:37.696: ERROR/ActivityManager(42): Start proc com.android.deskclock for broadcast com.android.deskclock/.AlarmInitReceiver: pid=261 uid=10019 gids={}Load: 9.09 / 2.65 / 0.91
    06-21 13:14:37.696: ERROR/ActivityManager(42): CPU usage from 1306ms to -7682ms ago:
    06-21 13:14:37.696: ERROR/ActivityManager(42): 45% 42/system_server: 25% user + 19% kernel / faults: 863 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 22% 125/zygote: 16% user + 6.2% kernel / faults: 1268 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 4% 231/zygote: 2.1% user + 1.9% kernel / faults: 493 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 2.8% 115/zygote: 1.3% user + 1.4% kernel / faults: 63 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 1.2% 117/zygote: 0.5% user + 0.6% kernel / faults: 40 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.2% 27/servicemanager: 0.1% user + 0.1% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.1% 32/zygote: 0% user + 0.1% kernel / faults: 16 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0% 4/events/0: 0% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0% 45/adbd: 0% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.1% 227/zygote: 0.1% user + 0% kernel / faults: 8 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): +0% 261/com.android.deskclock: 0% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0% 205/android.process.media: 0.-2% user + 0.2% kernel / faults: 4 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 100% TOTAL: 58% user + 41% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): CPU usage from 6193ms to 7263ms later:
    06-21 13:14:37.696: ERROR/ActivityManager(42): 59% 42/system_server: 41% user + 17% kernel / faults: 46 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 22% 57/SurfaceFlinger: 20% user + 1.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 11% 73/ActivityManager: 4.9% user + 6.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 3.9% 54/Binder Thread #: 3.9% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 3.9% 169/Binder Thread #: 1.9% user + 1.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 1.9% 44/HeapWorker: 0% user + 1.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 1.9% 56/Binder Thread #: 1.9% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 1.9% 156/Binder Thread #: 0.9% user + 0.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 42/system_server: 0.9% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 51/Compiler: 0.9% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 72/er.ServerThread: 0% user + 0.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 90/InputDispatcher: 0% user + 0.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 126/GpsLocationProv: 0% user + 0.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 170/Binder Thread #: 0.9% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 220/Binder Thread #: 0% user + 0.9% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.9% 223/Binder Thread #: 0.9% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 29% 125/com.android.launcher: 16% user + 13% kernel / faults: 308 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 22% 125/ndroid.launcher: 11% user + 10% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 3.8% 261/com.android.deskclock: 3.8% user + 0% kernel / faults: 1 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 2.5% 261/droid.deskclock: 2.5% user + 0% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.7% 117/com.android.systemui: 0% user + 0.7% kernel / faults: 26 minor
    06-21 13:14:37.696: ERROR/ActivityManager(42): 1.5% 117/ndroid.systemui: 0.7% user + 0.7% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.3% 152/Binder Thread #: 0% user + 0.3% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 0.1% 4/events/0: 0% user + 0.1% kernel
    06-21 13:14:37.696: ERROR/ActivityManager(42): 100% TOTAL: 57% user + 42% kernel
    06-21 13:14:37.708: INFO/Process(42): Sending signal. PID: 231 SIG: 9
    06-21 13:14:37.946: DEBUG/AlarmManagerService(42): Kernel timezone updated to -330 minutes west of GMT
    06-21 13:14:37.977: DEBUG/SystemClock(115): Setting time of day to sec=1308642278
    06-21 13:14:38.143: WARN/SystemClock(115): Unable to set rtc to 1308642278: Invalid argument
    06-21 13:14:39.233: INFO/ActivityManager(42): Process com.android.mms (pid 231) has died.
    06-21 13:14:39.544: INFO/ActivityManager(42): Process android.process.media (pid 205) has died.
    06-21 13:14:39.553: WARN/ActivityManager(42): Scheduling restart of crashed service com.android.providers.downloads/.DownloadService in 5000ms
    06-21 13:14:39.593: INFO/ActivityManager(42): Start proc com.android.email for broadcast com.android.email/.service.EmailBroadcastReceiver: pid=275 uid=10028 gids={3003, 1015}
    06-21 13:14:39.943: DEBUG/SntpClient(42): request time failed: java.net.SocketException: Address family not supported by protocol
    06-21 13:14:40.693: INFO/ActivityThread(275): Pub com.android.email.provider: com.android.email.provider.EmailProvider
    06-21 13:14:40.735: INFO/ActivityThread(275): Pub com.android.email.attachmentprovider: com.android.email.provider.AttachmentProvider
    06-21 13:14:40.743: INFO/ActivityThread(275): Pub com.android.exchange.provider: com.android.exchange.provider.ExchangeProvider
    06-21 13:14:41.133: DEBUG/EAS SyncManager(275): !!! EAS SyncManager, onCreate
    06-21 13:14:41.373: DEBUG/dalvikvm(227): GC_EXPLICIT freed 324K, 54% free 2542K/5511K, external 716K/1038K, paused 558ms
    06-21 13:14:42.863: INFO/ActivityManager(42): Start proc com.android.quicksearchbox for broadcast com.android.quicksearchbox/.SearchWidgetProvider: pid=286 uid=10002 gids={3003}
    06-21 13:14:43.073: DEBUG/Eas Debug(275): Logging:
    06-21 13:14:43.634: DEBUG/dalvikvm(275): GC_CONCURRENT freed 491K, 53% free 2744K/5831K, external 716K/1038K, paused 10ms+29ms
    06-21 13:14:43.773: DEBUG/EAS SyncManager(275): !!! EAS SyncManager, onDestroy
    06-21 13:14:44.093: INFO/ActivityThread(286): Pub com.android.quicksearchbox.google: com.android.quicksearchbox.google.GoogleSuggestionProvider
    06-21 13:14:44.143: INFO/ActivityThread(286): Pub com.android.quicksearchbox.shortcuts: com.android.quicksearchbox.ShortcutsProvider
    06-21 13:14:44.404: INFO/ActivityManager(42): Start proc com.android.music for broadcast com.android.music/.MediaAppWidgetProvider: pid=298 uid=10005 gids={3003, 1015}
    06-21 13:14:44.594: INFO/ActivityManager(42): Start proc android.process.media for service com.android.providers.downloads/.DownloadService: pid=301 uid=10000 gids={1015, 1006, 2001, 3003}
    06-21 13:14:46.614: WARN/dalvikvm(286): threadid=6: spin on suspend #1 threadid=1 (pcf=0)
    06-21 13:14:46.614: DEBUG/dalvikvm(286): Temporarily moving tid 286 to fg (was 0)
    06-21 13:14:46.774: WARN/dalvikvm(286): threadid=6: spin on suspend resolved in 1324 msec
    06-21 13:14:46.774: DEBUG/dalvikvm(286): Restored policy of 286 to 0
    06-21 13:14:46.964: INFO/ActivityThread(301): Pub media: com.android.providers.media.MediaProvider
    06-21 13:14:47.453: VERBOSE/MediaProvider(301): Attached volume: internal
    06-21 13:14:47.555: INFO/ActivityThread(301): Pub downloads: com.android.providers.downloads.DownloadProvider
    06-21 13:14:47.654: INFO/ActivityManager(42): Start proc com.android.protips for broadcast com.android.protips/.ProtipWidget: pid=315 uid=10024 gids={}
    06-21 13:14:47.744: INFO/ActivityThread(301): Pub drm: com.android.providers.drm.DrmProvider
    06-21 13:14:49.674: INFO/dalvikvm(42): Jit: resizing JitTable from 512 to 1024
    06-21 13:14:49.764: WARN/ActivityManager(42): No content provider found for:
    06-21 13:14:50.214: WARN/ActivityManager(42): No content provider found for:
    06-21 13:14:50.304: DEBUG/PackageParser(42): Scanning package: /data/app/vmdl320512019.tmp
    06-21 13:14:50.444: DEBUG/Email(275): BOOT_COMPLETED
    06-21 13:14:50.784: INFO/PackageParser(42): com.list: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
    06-21 13:14:51.234: DEBUG/dalvikvm(172): GC_CONCURRENT freed 232K, 51% free 2806K/5703K, external 716K/1038K, paused 10ms+18ms
    06-21 13:14:51.945: DEBUG/PackageManager(42): Scanning package com.list
    06-21 13:14:51.984: INFO/PackageManager(42): Unpacking native libraries for /data/app/com.list-1.apk
    06-21 13:14:52.034: DEBUG/installd(34): DexInv: — BEGIN ‘/data/app/com.list-1.apk’ —
    06-21 13:14:52.454: DEBUG/dalvikvm(326): DexOpt: load 77ms, verify+opt 78ms
    06-21 13:14:52.484: DEBUG/installd(34): DexInv: — END ‘/data/app/com.list-1.apk’ (success) —
    06-21 13:14:52.494: DEBUG/PackageManager(42): Activities: com.list.city
    06-21 13:14:52.524: INFO/InputReader(42): Device reconfigured: id=0×0, name=qwerty2, display size is now 480×800
    06-21 13:14:52.533: INFO/InputManager-Callbacks(42): No virtual keys found for device qwerty2.
    06-21 13:14:53.254: DEBUG/dalvikvm(125): GC_EXTERNAL_ALLOC freed 339K, 51% free 2977K/5959K, external 3229K/3246K, paused 129ms
    06-21 13:14:54.324: DEBUG/dalvikvm(42): GC_CONCURRENT freed 1184K, 48% free 4348K/8263K, external 3511K/4711K, paused 13ms+11ms
    06-21 13:14:54.404: INFO/installd(34): move /data/dalvik-cache/data@app@com.list-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.list-1.apk@classes.dex
    06-21 13:14:54.404: DEBUG/PackageManager(42): New package installed in /data/app/com.list-1.apk
    06-21 13:14:55.073: DEBUG/dalvikvm(125): GC_EXTERNAL_ALLOC freed 60K, 51% free 2968K/5959K, external 3917K/3935K, paused 127ms
    06-21 13:14:55.884: DEBUG/EAS SyncManager(275): !!! EAS SyncManager, onCreate
    06-21 13:14:55.904: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:14:55.925: DEBUG/EAS SyncManager(275): !!! EAS SyncManager, onStartCommand
    06-21 13:14:56.474: INFO/ARMAssembler(42): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x43d6f520:0x43d6f6e8] in 2288902 ns
    06-21 13:14:56.643: DEBUG/EAS SyncManager(275): !!! EAS SyncManager, stopping self
    06-21 13:14:56.974: INFO/ActivityManager(42): Displayed com.android.launcher/com.android.launcher2.Launcher: +1m16s418ms
    06-21 13:14:56.983: DEBUG/EAS SyncManager(275): !!! EAS SyncManager, onDestroy
    06-21 13:14:57.593: DEBUG/dalvikvm(125): GC_EXPLICIT freed 95K, 52% free 2909K/5959K, external 4163K/4512K, paused 815ms
    06-21 13:14:57.793: DEBUG/dalvikvm(42): GC_EXPLICIT freed 254K, 49% free 4273K/8263K, external 3511K/4711K, paused 413ms
    06-21 13:14:58.033: WARN/RecognitionManagerService(42): no available voice recognition services found
    06-21 13:14:59.233: INFO/ActivityManager(42): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=332 uid=10009 gids={}
    06-21 13:14:59.823: DEBUG/AndroidRuntime(197): Shutting down VM
    06-21 13:14:59.873: DEBUG/dalvikvm(197): GC_CONCURRENT freed 100K, 72% free 294K/1024K, external 0K/0K, paused 4ms+2ms
    06-21 13:14:59.873: INFO/AndroidRuntime(197): NOTE: attach of thread ‘Binder Thread #3′ failed
    06-21 13:14:59.903: DEBUG/dalvikvm(197): Debugger has detached; object registry had 1 entries
    06-21 13:15:00.743: INFO/ActivityThread(332): Pub com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
    06-21 13:15:01.663: DEBUG/AndroidRuntime(344): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<< /data/dalvik-cache/data@app@com.list-2.apk@classes.dex
    06-21 13:24:13.283: DEBUG/PackageManager(42): New package installed in /data/app/com.list-2.apk
    06-21 13:24:13.583: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:24:13.773: DEBUG/dalvikvm(42): GC_EXPLICIT freed 640K, 49% free 4286K/8263K, external 2697K/3326K, paused 154ms
    06-21 13:24:13.953: DEBUG/dalvikvm(125): GC_EXPLICIT freed 141K, 51% free 2929K/5959K, external 3989K/4512K, paused 203ms
    06-21 13:24:14.173: DEBUG/dalvikvm(172): GC_EXPLICIT freed 185K, 52% free 2769K/5703K, external 716K/1038K, paused 181ms
    06-21 13:24:14.363: WARN/RecognitionManagerService(42): no available voice recognition services found
    06-21 13:24:15.004: DEBUG/dalvikvm(42): GC_EXPLICIT freed 202K, 49% free 4254K/8263K, external 2239K/2796K, paused 162ms
    06-21 13:24:15.063: INFO/installd(34): unlink /data/dalvik-cache/data@app@com.list-1.apk@classes.dex
    06-21 13:24:15.073: DEBUG/AndroidRuntime(393): Shutting down VM
    06-21 13:24:15.113: DEBUG/dalvikvm(393): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 3ms+2ms
    06-21 13:24:15.123: INFO/AndroidRuntime(393): NOTE: attach of thread ‘Binder Thread #4′ failed
    06-21 13:24:15.123: DEBUG/jdwp(393): Got wake-up signal, bailing out of select
    06-21 13:24:15.123: DEBUG/dalvikvm(393): Debugger has detached; object registry had 1 entries
    06-21 13:24:16.343: DEBUG/AndroidRuntime(408): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    06-21 13:24:16.343: DEBUG/AndroidRuntime(408): CheckJNI is ON
    06-21 13:24:17.704: DEBUG/AndroidRuntime(408): Calling main entry com.android.commands.am.Am
    06-21 13:24:17.773: INFO/ActivityManager(42): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10000000 cmp=com.list/.city } from pid 408
    06-21 13:24:18.063: DEBUG/AndroidRuntime(408): Shutting down VM
    06-21 13:24:18.093: INFO/ActivityManager(42): Start proc com.list for activity com.list/.city: pid=417 uid=10044 gids={1015}
    06-21 13:24:18.153: INFO/AndroidRuntime(408): NOTE: attach of thread 'Binder Thread #3' failed
    06-21 13:24:18.173: DEBUG/dalvikvm(408): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 3ms+3ms
    06-21 13:24:18.304: DEBUG/jdwp(408): Got wake-up signal, bailing out of select
    06-21 13:24:18.304: DEBUG/dalvikvm(408): Debugger has detached; object registry had 1 entries
    06-21 13:24:18.883: DEBUG/dalvikvm(32): GC_EXPLICIT freed 11K, 53% free 2538K/5379K, external 716K/1038K, paused 684ms
    06-21 13:24:19.143: DEBUG/dalvikvm(32): GC_EXPLICIT freed <1K, 53% free 2538K/5379K, external 716K/1038K, paused 260ms
    06-21 13:24:19.443: DEBUG/dalvikvm(32): GC_EXPLICIT freed <1K, 53% free 2538K/5379K, external 716K/1038K, paused 293ms
    06-21 13:24:22.274: ERROR/log_tag(417): Error in http connectionjava.net.SocketException: Permission denied
    06-21 13:24:22.274: ERROR/log_tag(417): Error converting result java.lang.NullPointerException
    06-21 13:24:22.284: DEBUG/AndroidRuntime(417): Shutting down VM
    06-21 13:24:22.284: WARN/dalvikvm(417): threadid=1: thread exiting with uncaught exception (group=0×40015560)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): FATAL EXCEPTION: main
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/com.list.city}: java.lang.NullPointerException
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.os.Handler.dispatchMessage(Handler.java:99)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.os.Looper.loop(Looper.java:123)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.ActivityThread.main(ActivityThread.java:3683)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at java.lang.reflect.Method.invokeNative(Native Method)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at java.lang.reflect.Method.invoke(Method.java:507)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at dalvik.system.NativeStart.main(Native Method)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): Caused by: java.lang.NullPointerException
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at org.json.JSONTokener.nextValue(JSONTokener.java:90)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at org.json.JSONArray.(JSONArray.java:87)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at org.json.JSONArray.(JSONArray.java:103)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at com.list.city.onCreate(city.java:62)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    06-21 13:24:22.304: ERROR/AndroidRuntime(417): … 11 more
    06-21 13:24:22.324: WARN/ActivityManager(42): Force finishing activity com.list/.city
    06-21 13:24:22.884: WARN/ActivityManager(42): Activity pause timeout for HistoryRecord{4069f708 com.list/.city}
    06-21 13:24:24.854: WARN/InputManagerService(42): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406308a0
    06-21 13:24:25.214: INFO/Process(417): Sending signal. PID: 417 SIG: 9
    06-21 13:24:25.424: INFO/ActivityManager(42): Process com.list (pid 417) has died.
    06-21 13:24:30.664: DEBUG/dalvikvm(227): GC_EXPLICIT freed 7K, 54% free 2544K/5511K, external 716K/1038K, paused 104ms
    06-21 13:24:33.819: WARN/ActivityManager(42): Activity destroy timeout for HistoryRecord{4069f708 com.list/.city}
    06-21 13:24:35.843: DEBUG/dalvikvm(286): GC_EXPLICIT freed 501K, 55% free 2598K/5703K, external 716K/1038K, paused 248ms
    06-21 13:24:40.023: DEBUG/SntpClient(42): request time failed: java.net.SocketException: Address family not supported by protocol
    06-21 13:24:40.773: DEBUG/dalvikvm(332): GC_EXPLICIT freed 323K, 54% free 2539K/5511K, external 716K/1038K, paused 114ms
    06-21 13:25:17.943: INFO/dalvikvm(42): Jit: resizing JitTable from 1024 to 2048
    06-21 13:27:36.853: DEBUG/AndroidRuntime(428): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<< /data/dalvik-cache/data@app@com.list-1.apk@classes.dex
    06-21 13:27:40.003: DEBUG/PackageManager(42): New package installed in /data/app/com.list-1.apk
    06-21 13:27:40.265: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:27:40.454: DEBUG/dalvikvm(42): GC_EXPLICIT freed 566K, 48% free 4312K/8263K, external 2697K/2796K, paused 156ms
    06-21 13:27:40.634: DEBUG/dalvikvm(125): GC_EXPLICIT freed 98K, 51% free 2957K/5959K, external 4007K/4512K, paused 199ms
    06-21 13:27:40.853: DEBUG/dalvikvm(172): GC_EXPLICIT freed 121K, 52% free 2769K/5703K, external 716K/1038K, paused 181ms
    06-21 13:27:41.115: WARN/RecognitionManagerService(42): no available voice recognition services found
    06-21 13:27:41.704: DEBUG/dalvikvm(42): GC_EXPLICIT freed 193K, 49% free 4288K/8263K, external 2687K/2796K, paused 161ms
    06-21 13:27:41.763: INFO/installd(34): unlink /data/dalvik-cache/data@app@com.list-2.apk@classes.dex
    06-21 13:27:41.783: DEBUG/AndroidRuntime(428): Shutting down VM
    06-21 13:27:41.814: DEBUG/dalvikvm(428): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 4ms+2ms
    06-21 13:27:41.824: INFO/AndroidRuntime(428): NOTE: attach of thread ‘Binder Thread #3′ failed
    06-21 13:27:41.824: DEBUG/jdwp(428): Got wake-up signal, bailing out of select
    06-21 13:27:41.824: DEBUG/dalvikvm(428): Debugger has detached; object registry had 1 entries
    06-21 13:27:43.024: DEBUG/AndroidRuntime(442): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    06-21 13:27:43.024: DEBUG/AndroidRuntime(442): CheckJNI is ON
    06-21 13:27:44.404: DEBUG/AndroidRuntime(442): Calling main entry com.android.commands.am.Am
    06-21 13:27:44.494: INFO/ActivityManager(42): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10000000 cmp=com.list/.city } from pid 442
    06-21 13:27:44.594: DEBUG/AndroidRuntime(442): Shutting down VM
    06-21 13:27:44.684: INFO/ActivityManager(42): Start proc com.list for activity com.list/.city: pid=450 uid=10044 gids={1015}
    06-21 13:27:44.694: INFO/AndroidRuntime(442): NOTE: attach of thread 'Binder Thread #3' failed
    06-21 13:27:44.754: DEBUG/dalvikvm(442): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 4ms+2ms
    06-21 13:27:44.774: DEBUG/jdwp(442): Got wake-up signal, bailing out of select
    06-21 13:27:44.774: DEBUG/dalvikvm(442): Debugger has detached; object registry had 1 entries
    06-21 13:27:48.684: ERROR/log_tag(450): Error in http connectionjava.net.SocketException: Permission denied
    06-21 13:27:48.684: ERROR/log_tag(450): Error converting result java.lang.NullPointerException
    06-21 13:27:48.695: DEBUG/AndroidRuntime(450): Shutting down VM
    06-21 13:27:48.695: WARN/dalvikvm(450): threadid=1: thread exiting with uncaught exception (group=0×40015560)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): FATAL EXCEPTION: main
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/com.list.city}: java.lang.NullPointerException
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.os.Handler.dispatchMessage(Handler.java:99)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.os.Looper.loop(Looper.java:123)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.ActivityThread.main(ActivityThread.java:3683)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at java.lang.reflect.Method.invokeNative(Native Method)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at java.lang.reflect.Method.invoke(Method.java:507)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at dalvik.system.NativeStart.main(Native Method)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): Caused by: java.lang.NullPointerException
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at org.json.JSONTokener.nextValue(JSONTokener.java:90)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at org.json.JSONArray.(JSONArray.java:87)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at org.json.JSONArray.(JSONArray.java:103)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at com.list.city.onCreate(city.java:62)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    06-21 13:27:48.734: ERROR/AndroidRuntime(450): … 11 more
    06-21 13:27:48.754: WARN/ActivityManager(42): Force finishing activity com.list/.city
    06-21 13:27:49.284: WARN/ActivityManager(42): Activity pause timeout for HistoryRecord{4069f708 com.list/.city}
    06-21 13:27:52.543: WARN/InputManagerService(42): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40689eb8
    06-21 13:27:53.004: INFO/Process(450): Sending signal. PID: 450 SIG: 9
    06-21 13:27:53.244: INFO/ActivityManager(42): Process com.list (pid 450) has died.
    06-21 13:27:56.423: DEBUG/dalvikvm(227): GC_EXPLICIT freed 6K, 54% free 2543K/5511K, external 716K/1038K, paused 104ms
    06-21 13:28:00.967: WARN/ActivityManager(42): Activity destroy timeout for HistoryRecord{4069f708 com.list/.city}
    06-21 13:28:05.323: DEBUG/dalvikvm(286): GC_EXPLICIT freed 12K, 55% free 2595K/5703K, external 716K/1038K, paused 128ms
    06-21 13:28:10.354: DEBUG/dalvikvm(332): GC_EXPLICIT freed 3K, 54% free 2537K/5511K, external 716K/1038K, paused 126ms
    06-21 13:29:40.043: DEBUG/SntpClient(42): request time failed: java.net.SocketException: Address family not supported by protocol
    06-21 13:34:40.074: DEBUG/SntpClient(42): request time failed: java.net.SocketException: Address family not supported by protocol
    06-21 13:39:40.093: DEBUG/SntpClient(42): request time failed: java.net.SocketException: Address family not supported by protocol
    06-21 13:39:45.854: DEBUG/AndroidRuntime(462): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<< /data/dalvik-cache/data@app@com.list-2.apk@classes.dex
    06-21 13:39:48.484: DEBUG/PackageManager(42): New package installed in /data/app/com.list-2.apk
    06-21 13:39:48.703: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:39:48.913: DEBUG/dalvikvm(42): GC_EXPLICIT freed 614K, 48% free 4350K/8263K, external 2697K/2796K, paused 172ms
    06-21 13:39:49.073: DEBUG/dalvikvm(125): GC_EXPLICIT freed 43K, 50% free 2986K/5959K, external 4007K/4512K, paused 179ms
    06-21 13:39:49.294: DEBUG/dalvikvm(172): GC_EXPLICIT freed 121K, 52% free 2769K/5703K, external 716K/1038K, paused 175ms
    06-21 13:39:49.494: WARN/RecognitionManagerService(42): no available voice recognition services found
    06-21 13:39:50.083: DEBUG/dalvikvm(42): GC_EXPLICIT freed 192K, 48% free 4328K/8263K, external 2687K/2796K, paused 268ms
    06-21 13:39:50.144: INFO/installd(34): unlink /data/dalvik-cache/data@app@com.list-1.apk@classes.dex
    06-21 13:39:50.154: DEBUG/AndroidRuntime(462): Shutting down VM
    06-21 13:39:50.194: DEBUG/dalvikvm(462): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 3ms+3ms
    06-21 13:39:50.204: INFO/AndroidRuntime(462): NOTE: attach of thread ‘Binder Thread #3′ failed
    06-21 13:39:50.204: DEBUG/jdwp(462): Got wake-up signal, bailing out of select
    06-21 13:39:50.204: DEBUG/dalvikvm(462): Debugger has detached; object registry had 1 entries
    06-21 13:39:51.384: DEBUG/AndroidRuntime(476): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    06-21 13:39:51.384: DEBUG/AndroidRuntime(476): CheckJNI is ON
    06-21 13:39:52.764: DEBUG/AndroidRuntime(476): Calling main entry com.android.commands.am.Am
    06-21 13:39:52.844: INFO/ActivityManager(42): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10000000 cmp=com.list/.city } from pid 476
    06-21 13:39:52.984: DEBUG/AndroidRuntime(476): Shutting down VM
    06-21 13:39:53.024: INFO/ActivityManager(42): Start proc com.list for activity com.list/.city: pid=485 uid=10044 gids={1015}
    06-21 13:39:53.054: INFO/AndroidRuntime(476): NOTE: attach of thread 'Binder Thread #3' failed
    06-21 13:39:53.074: DEBUG/dalvikvm(476): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 2ms+3ms
    06-21 13:39:53.154: DEBUG/jdwp(476): Got wake-up signal, bailing out of select
    06-21 13:39:53.154: DEBUG/dalvikvm(476): Debugger has detached; object registry had 1 entries
    06-21 13:39:56.655: DEBUG/AndroidRuntime(485): Shutting down VM
    06-21 13:39:56.655: WARN/dalvikvm(485): threadid=1: thread exiting with uncaught exception (group=0×40015560)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): FATAL EXCEPTION: main
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/com.list.city}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.os.Handler.dispatchMessage(Handler.java:99)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.os.Looper.loop(Looper.java:123)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ActivityThread.main(ActivityThread.java:3683)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at java.lang.reflect.Method.invokeNative(Native Method)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at java.lang.reflect.Method.invoke(Method.java:507)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at dalvik.system.NativeStart.main(Native Method)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.Activity.setContentView(Activity.java:1657)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at com.list.city.onCreate(city.java:29)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    06-21 13:39:56.674: ERROR/AndroidRuntime(485): … 11 more
    06-21 13:39:56.694: WARN/ActivityManager(42): Force finishing activity com.list/.city
    06-21 13:39:57.233: WARN/ActivityManager(42): Activity pause timeout for HistoryRecord{40699660 com.list/.city}
    06-21 13:39:59.414: WARN/InputManagerService(42): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40695670
    06-21 13:39:59.744: INFO/Process(485): Sending signal. PID: 485 SIG: 9
    06-21 13:39:59.934: INFO/ActivityManager(42): Process com.list (pid 485) has died.
    06-21 13:40:05.313: DEBUG/dalvikvm(227): GC_EXPLICIT freed 6K, 54% free 2543K/5511K, external 716K/1038K, paused 88ms
    06-21 13:40:09.213: WARN/ActivityManager(42): Activity destroy timeout for HistoryRecord{40699660 com.list/.city}
    06-21 13:40:10.443: DEBUG/dalvikvm(286): GC_EXPLICIT freed 6K, 55% free 2597K/5703K, external 716K/1038K, paused 164ms
    06-21 13:40:15.424: DEBUG/dalvikvm(332): GC_EXPLICIT freed >>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<< /data/dalvik-cache/data@app@com.list-1.apk@classes.dex
    06-21 13:49:55.994: DEBUG/PackageManager(42): New package installed in /data/app/com.list-1.apk
    06-21 13:49:56.264: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:49:56.534: DEBUG/dalvikvm(125): GC_EXPLICIT freed 50K, 51% free 2945K/5959K, external 3958K/4512K, paused 258ms
    06-21 13:49:56.584: DEBUG/dalvikvm(42): GC_EXPLICIT freed 686K, 47% free 4395K/8263K, external 2697K/2796K, paused 250ms
    06-21 13:49:56.883: DEBUG/dalvikvm(172): GC_EXPLICIT freed 121K, 52% free 2769K/5703K, external 716K/1038K, paused 187ms
    06-21 13:49:57.074: WARN/RecognitionManagerService(42): no available voice recognition services found
    06-21 13:49:57.644: DEBUG/dalvikvm(42): GC_EXPLICIT freed 225K, 48% free 4340K/8263K, external 2687K/2796K, paused 169ms
    06-21 13:49:57.934: INFO/installd(34): unlink /data/dalvik-cache/data@app@com.list-2.apk@classes.dex
    06-21 13:49:57.964: DEBUG/AndroidRuntime(525): Shutting down VM
    06-21 13:49:58.004: INFO/AndroidRuntime(525): NOTE: attach of thread ‘Binder Thread #3′ failed
    06-21 13:49:58.004: DEBUG/dalvikvm(525): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 4ms+7ms
    06-21 13:49:58.014: DEBUG/jdwp(525): Got wake-up signal, bailing out of select
    06-21 13:49:58.014: DEBUG/dalvikvm(525): Debugger has detached; object registry had 1 entries
    06-21 13:49:59.314: DEBUG/AndroidRuntime(539): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    06-21 13:51:12.584: DEBUG/AndroidRuntime(560): CheckJNI is ON
    06-21 13:51:13.964: DEBUG/AndroidRuntime(560): Calling main entry com.android.commands.pm.Pm
    06-21 13:51:14.284: DEBUG/dalvikvm(227): GC_EXPLICIT freed 4K, 54% free 2544K/5511K, external 716K/1038K, paused 112ms
    06-21 13:51:14.304: WARN/ActivityManager(42): No content provider found for:
    06-21 13:51:14.324: WARN/ActivityManager(42): No content provider found for:
    06-21 13:51:14.374: DEBUG/PackageParser(42): Scanning package: /data/app/vmdl2139789233.tmp
    06-21 13:51:14.384: WARN/PackageParser(42): Unknown element under : uses-permission at /data/app/vmdl2139789233.tmp Binary XML file line #17
    06-21 13:51:14.384: INFO/PackageParser(42): com.list: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
    06-21 13:51:14.524: INFO/PackageManager(42): Removing non-system package:com.list
    06-21 13:51:14.524: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:51:14.694: DEBUG/PackageManager(42): Scanning package com.list
    06-21 13:51:14.704: INFO/PackageManager(42): Package com.list codePath changed from /data/app/com.list-1.apk to /data/app/com.list-2.apk; Retaining data and using new
    06-21 13:51:14.704: INFO/PackageManager(42): Unpacking native libraries for /data/app/com.list-2.apk
    06-21 13:51:14.724: DEBUG/installd(34): DexInv: — BEGIN ‘/data/app/com.list-2.apk’ —
    06-21 13:51:15.114: DEBUG/dalvikvm(569): DexOpt: load 66ms, verify+opt 66ms
    06-21 13:51:15.134: DEBUG/installd(34): DexInv: — END ‘/data/app/com.list-2.apk’ (success) —
    06-21 13:51:15.134: WARN/PackageManager(42): Code path for pkg : com.list changing from /data/app/com.list-1.apk to /data/app/com.list-2.apk
    06-21 13:51:15.134: WARN/PackageManager(42): Resource path for pkg : com.list changing from /data/app/com.list-1.apk to /data/app/com.list-2.apk
    06-21 13:51:15.134: DEBUG/PackageManager(42): Activities: com.list.city
    06-21 13:51:15.154: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:51:15.344: INFO/installd(34): move /data/dalvik-cache/data@app@com.list-2.apk@classes.dex -> /data/dalvik-cache/data@app@com.list-2.apk@classes.dex
    06-21 13:51:15.354: DEBUG/PackageManager(42): New package installed in /data/app/com.list-2.apk
    06-21 13:51:15.594: INFO/ActivityManager(42): Force stopping package com.list uid=10044
    06-21 13:51:15.794: DEBUG/dalvikvm(42): GC_EXPLICIT freed 539K, 47% free 4388K/8263K, external 2697K/2796K, paused 158ms
    06-21 13:51:15.945: DEBUG/dalvikvm(125): GC_EXPLICIT freed 73K, 51% free 2952K/5959K, external 4007K/4512K, paused 168ms
    06-21 13:51:16.154: DEBUG/dalvikvm(172): GC_EXPLICIT freed 121K, 52% free 2769K/5703K, external 716K/1038K, paused 182ms
    06-21 13:51:16.364: WARN/RecognitionManagerService(42): no available voice recognition services found
    06-21 13:51:16.974: DEBUG/dalvikvm(42): GC_EXPLICIT freed 187K, 48% free 4370K/8263K, external 2687K/2796K, paused 173ms
    06-21 13:51:17.034: INFO/installd(34): unlink /data/dalvik-cache/data@app@com.list-1.apk@classes.dex
    06-21 13:51:17.044: DEBUG/AndroidRuntime(560): Shutting down VM
    06-21 13:51:17.084: DEBUG/dalvikvm(560): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 4ms+5ms
    06-21 13:51:17.094: INFO/AndroidRuntime(560): NOTE: attach of thread ‘Binder Thread #3′ failed
    06-21 13:51:17.094: DEBUG/jdwp(560): Got wake-up signal, bailing out of select
    06-21 13:51:17.094: DEBUG/dalvikvm(560): Debugger has detached; object registry had 1 entries
    06-21 13:51:18.164: DEBUG/AndroidRuntime(574): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    06-21 13:51:18.164: DEBUG/AndroidRuntime(574): CheckJNI is ON
    06-21 13:51:19.633: DEBUG/AndroidRuntime(574): Calling main entry com.android.commands.am.Am
    06-21 13:51:19.713: INFO/ActivityManager(42): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0×10000000 cmp=com.list/.city } from pid 574
    06-21 13:51:19.803: DEBUG/AndroidRuntime(574): Shutting down VM
    06-21 13:51:19.883: INFO/AndroidRuntime(574): NOTE: attach of thread 'Binder Thread #3' failed
    06-21 13:51:19.923: DEBUG/dalvikvm(574): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 3ms+2ms
    06-21 13:51:19.943: DEBUG/jdwp(574): Got wake-up signal, bailing out of select
    06-21 13:51:19.943: DEBUG/dalvikvm(574): Debugger has detached; object registry had 1 entries
    06-21 13:51:20.093: INFO/ActivityManager(42): Start proc com.list for activity com.list/.city: pid=583 uid=10044 gids={1015}
    06-21 13:51:23.703: DEBUG/AndroidRuntime(583): Shutting down VM
    06-21 13:51:23.703: WARN/dalvikvm(583): threadid=1: thread exiting with uncaught exception (group=0×40015560)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): FATAL EXCEPTION: main
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.list/com.list.city}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.os.Handler.dispatchMessage(Handler.java:99)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.os.Looper.loop(Looper.java:123)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ActivityThread.main(ActivityThread.java:3683)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at java.lang.reflect.Method.invokeNative(Native Method)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at java.lang.reflect.Method.invoke(Method.java:507)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at dalvik.system.NativeStart.main(Native Method)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.Activity.setContentView(Activity.java:1657)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at com.list.city.onCreate(city.java:29)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    06-21 13:51:23.723: ERROR/AndroidRuntime(583): … 11 more
    06-21 13:51:23.743: WARN/ActivityManager(42): Force finishing activity com.list/.city
    06-21 13:51:24.273: WARN/ActivityManager(42): Activity pause timeout for HistoryRecord{406e9b10 com.list/.city}
    06-21 13:51:25.733: INFO/Process(583): Sending signal. PID: 583 SIG: 9
    06-21 13:51:25.763: INFO/ActivityManager(42): Process com.list (pid 583) has died.
    06-21 13:51:26.285: WARN/InputManagerService(42): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40565820
    06-21 13:51:31.663: DEBUG/dalvikvm(227): GC_EXPLICIT freed 6K, 54% free 2543K/5511K, external 716K/1038K, paused 93ms

    my process is getting terminated and showing error " process com.list has stopped unexpectedly …
    my php file is

  48. Manish

    Hey the code is not working , i m getting errors in these lines :
    int ct_id ;
    String ct_name ;

    error says “ct_id ” and “ct_name” never used

  49. Nazir

    hii
    its really good work by u.
    but when i am trying to do this its gives android
    exception. and it works fine in the browser
    actually my server is at remote machine
    plz reply me soon

  50. Nazir

    it doesnt show any error but
    in the emulator it shows that the citynot found
    exception
    plz help me

  51. Nazir

    it shows
    city not found
    plz help me out…

  52. hakuya

    why for me it didnt work?
    in logcat it said error at com.list.city.onCreate(city.java:30)
    when I traced it, the location is setContentView(R.layout.main);

    1. hakuya

      please help me :cry:

  53. prasanna

    hi barghav,

    how can i conneccect MS SQL , can u give me some idea

  54. gfxne.ws

    very nice a software i am useing this one thanks

  55. Vishnu

    Thanks a lot…… :razz:

  56. bhargav srivatsav

    hello bargav

    Iam trying to use your application but its force closing.I am using wap server i places your php file in www folder in wamp server and created a database with table in mysql.BUt still i am trying to connect using 10.0.2.2/www/city.php.

    could you please reply me as soon as possible.thanx!!

    1. bhargav

      You should use following url to call php file.
      http://10.0.2.2/city.php

  57. aaron

    I am getting a networkonmainthredexception error in logcat, do you know why it is happening.
    Thanks,

    1. bhargav

      Thanks for using code. You can get more information of NetworkOnMainThreadException error from this link.
      Might be you are doing potentially long running operations such as network or database operations, or computationally expensive calculations such as resizing bitmaps. I think the code that you are executing is not efficient.

  58. Sajol

    hi,
    At last i can do it.your blog help me as my teacher.
    thank you sir.
    hope that you will teach us many things. :grin:

  59. haytham

    guys , where is the code that displays the data on my screen ??

  60. RYS

    Hi, Im new to android….just wonder why I copy and paste your coding, why get yellow underline on (int ct_id and String ct_name) :???:
    and izzit the layout.xml (design page) have to do myself one??
    Hope you can help me out. :|

  61. RYS

    Anyone know why gt yellow underline on int ct_id and string ct_name ????? Your helped will be appreciated.

  62. sandeep

    Great codes yar….
    thanks bhargav
    Really useful one.

    Can i get a code snippet which will give me exact location of my device.
    I tried it but m only getting city name not exact place of city.
    Plz provide if u can.
    Thanks.

  63. RYS

    Sandeep, you can run all the code without error???

  64. Sandeep

    RYS,
    Dont worry abt that yello line , its a wrning.
    By the way reason is that u must have jst declared tht varaiables and not used . And if not then jst move ur cursor to the indicator coming at the start of line u’ll get the rezn.

  65. Sarvesh Singh

    Hi ,
    I’m new on android and I read and use your tutorial , but whenever I run my app there is an error occur Sorry the application has stopped unexpetdly. please try again. Force close

    Can you tell me what is the problem here.

    Thanks

  66. Barbara Morey

    Hei!

    I am using wamp server and when I access with the web browser to: http://localhost/connection.php it shows me a result. Everything ok.

    But when I access from the android application I get: java.net.SocketException: Network unreachable

    And I also put the:
    in the android manifest file.

    Can anybody helpme with this please?

    1. Barbara Morey

      It is important to say that the before error is shown when I use:
      httppost= new HttpPost(“http://10.0.2.2/connection.php”);

      If I use: httppost= new HttpPost(“http://localhost/connection.php”);
      I get: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused

      I am not using any emulator.

      I will appreciate any gelp. Thanks in advance

  67. Usman

    Hello Bhargav,

    This tutorial is amazing!

    I encoded the php to json and it works fine when I call it on browser, but when I run android code, it gives this error:
    “The application city is stopped Unexpectedly”

    Although the uses-permission is set to internet.

    I exactly copied your code

    Any idea?

    Thanks!

    1. Usman

      Or can you please provide the whole source code? It will be easier to learn and follow if we can get a working Java app with xml ?

      Please share some thoughts..

      Thanks!

  68. Ching

    Hi sir.. i just wanted to ask .. Is HTTP request is the term where in the android will request data from the php script? I was just confused with my conceptual framework right now.. because as i know the term used by the android to retrieve the json format from the php script is HTTP post… thanks :razz:

  69. banti bisht

    hi

    i have problem when i executed this codeee

    it say some null type error and can not converted in to jarry

    my php returnd data when i check it manualyy plz help mee

  70. Reval

    Hi

    Thanks so much for the code. It looks easy enough to make it work but some how it does not work form me. I know php and I am extremely new to android development.

    In the first couple lines of code you have this

    public class city extends ListActivity {

    For some reason Intellij Idea (IDE) underlines the word city and says that it should be city.java when I do that it still doesnt work.

    The error i get in the console is Error: (75, 5)class, interface, or enum expected

    Please i desperately need help. I have looked everywhere for how to connect android to mysql i desperately need to learn for uni please help it would be much appreciated :cry:

  71. Reval

    Hi again

    I have been trying all day to figure this out. I think it has something to do with naming the project or activity????????

    Btw I am using Andriod SDK 2.3.1 and JDK 1.6

  72. denial

    if need both side of client and server on android the what should we do ? , i am new to android and i not sure android support php , i need to send and received some data from database between android tablets , i chose one as server and and other as client and use tcp socket programming . my question is that possible to your way to communicate between server and client ,
    thanks if you could help

  73. sky

    Hi is it possible to provide the full xml code ?

  74. Daniel Lindegaard

    Seems to work now. I just had to change ListActivity to Activity. Thanks :-)

  75. sky

    Hi i am getting an error on this 2 lines of the code
    lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View view,int position, long id) {

    any help on how to solve this

  76. firzan

    i want to develope a chat application…like “WhatsApp”
    plz help me …!!!

  77. firzan

    whenever I run my app there is an error occur “Sorry the application has stopped unexpetdly. please try again. Force close”…

    plz help me…..!!!
    :sad:

    1. Reval Govender

      Same thing happens to me please help :sad: :sad:

  78. keyneom

    Would you be able to explain what changes to the code would be necessary to allow access to an https site without a valid certificate. I would like to do this for testing purposes.

    1. keyneom

      * with authentication from a username and password.

  79. Jet

    I have a error :sad:

    Error: value of type java.lang.String cannot be converted to JSONArray

    Can you help me!

  80. TP

    Hello, I am able to run the App and it connects to the DB. It shows “No City Found” when I have no entries in the DB, and when I have an entry it just shows blank. I guess the APP is successfully checking the records, however how do I get it to display them? …..thanks

    1. Ben

      I too would very much like to see how this script is used to output. I can understand what I read above, but setting up an XML file to connect with it I have no idea. This seems to be a common problem for young android developers. I see many great looking tutorials but no explanation of the layout or XML.

  81. Shiwantha

    Hi Bhargav,

    Thank you very much for your information. I looked at several sources on the web and there are lot blogs out there, however your explanation is very easy to understand and explain it well!! Thank you so much!

    However, I am running to a problem: I modified your code a little bit to match with my database which is already running on a web server. (Only the field names) When I ran it, it always show “No Item Found” (Similar to your “No City Found”) I changed the IP address of the server and the URL to PHP. And it still didn’t give the error “Cannot find the database” but “No Item Found”.

    How could this be ? shouldn’t it say “Error in Connection to the database” on the error log ? Could you give me a clue here ?

    Thank you !!

    1. Haura

      Got the same error as you Shiwantha. Have you solved it anyway ?

  82. Syed

    Hi,

    Very nice. Thanks.

    I was hoping to get a bit more help from you!

    While loading the data from the database, if its from active URL, it takes a while. Can you show me some light on high I can integrate a progress bar or something like that while the data is loading.

    Thanks,
    Syed

  83. kumar

    Hi,

    I am trying to send data from android to php database. I will not be receiving anything from php database. Does anyone have an example for this.

    Thank you
    kumar

  84. Umesh Suryawanshi (GH Raisoni Nagpur)

    I am beginer in android development. I am doing a task that stores and retrives values to/from mysql database using eclipse. I need steps. I tried above. I did not got where to do php coding. where to place php file. Is this complete coding of php file. When i run this code in android emulator. I application stops unfortunatly. …please show me steps. …. My email id is here (sunboy180887@gmail.com) Thank you

  85. Manoj.M

    :?: i ve been trying to develop an android application it requires a remote connection i ve been trying u r code but when i tried to run it in emulator i ve been receiving force close error
    as i am new to this i can’t able to justify with the problem
    i ve given my php code n android code below :
    moreover i am using xampp server to accomplish this

    php code:

    android code:

    package project.connectivity;

    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 connectActivity 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 nameValuePairs = new ArrayList();
    //http post
    try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(“http://192.168.0.150/login.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
    try{
    jArray = new JSONArray(result);
    JSONObject json_data=null;
    for(int i=0;i<jArray.length();i++){
    json_data = jArray.getJSONObject(i);
    Log.i("log_tag","id: "+json_data.getInt("user_id")+
    ", name: "+json_data.getString("username")+
    ", password: "+json_data.getString("password"));
    }
    }
    catch(JSONException e1){
    Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
    } catch (ParseException e1) {
    e1.printStackTrace();
    }
    }
    }

    one more thing i ve given the permission in the manifest.xml file also

    my database name is project
    my table name is login
    fields are user_id,username,password

  86. Saeid

    What we must put in main.xlm

    1
    2
    3
    4
    5
    6
    7
      <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

    </LinearLayout>

    is that enogh ? but .. its not working …
    how put that array into a listview ?????

  87. Manoj.M

    bhargav,

    i ve mentioned my prob in the post already that i m receiving force close i ve tried the same in eclipse Java EE i got logcat exception help me to find a soln/.

  88. srinivas

    sir can u provede the xml files or whole aapplication code of Connecting to MySQL using PHP…

  89. Shabana.G

    hi bhargav,

    I have two things that are currently showing the exclamation mark. Under the

    int ct_id; (i have my very own variable to declare)
    String ct_name;

    I’m not sure why it showed the warning sign so i put this “@SuppressWarnings(“unused”)” for both of the lines.

    I’m being forced to close the application. What seems to be the problem?

  90. Shabana.G

    Hi Bhargav,

    I manage to eliminate the errors in the logcat. No syntax error as well. However, I keep getting the message “No events found” (i’m displaying event details) but i have two records insert into the respective table and it can be displayed on the php page i created.

    As mentioned in your email, the code was slightly modified but i’ve already switch it back using your example code.

    My http is “http://10.0.2.2/event_details.php”. Even checked the php file and it works fine. I have no clue what’s the cause of the empty field.

  91. Paul A.

    Hello Bhargav,

    i seem to be getting the same error that a lot of people are having, i modified the code a little bit to match my database (which is not that much of a difference just name of variables) n i got the application to run and read the database but it seems that is not sending the data? it says cities not found, am i doing something wrong? i been reading something about changing the xml a little bit in order to print the json lists im not sure what this means, thank you for your help!

    1. Paul A.

      Hello again! i finally got it working, im not sure if anybody had this problem but when i create my php file, the software i use automatically adds a couple lines of code before the php code starts it kind of look like this:

      .
      .
      . other stuff

      all i did was delete the other stuff and it worked perfectly! hope this helps to anybody that was having problems with this! Great tutorial btw helped me a lot!

  92. dipali patel

    hello,,,
    i can not retrive image from mysql database using json data..

    so plz help me for regarding retrieve imafe from database..

    thank you.

  93. Gerard

    I made the same code and script i’ve tried on 10.0.2.2 and i put the script on a web server and i’m getting the same error java.net.socketexception…i am debugging on a real device..and if on emultor i still get the error :???:

  94. yuvaraj

    Hi, Bhargav i am also to establish a mysql connectivity from my android .And i tried your code .Only the toast part of the code is appearing in the emulator.But my variables and the localhost IP tht i entered are correct.Please help me out . :|

  95. Phedon Rousou

    Hello there,
    I have tried to implement this code on my project but with no success. I get the following error
    03-07 21:41:05.042: W/System.err(3914): org.json.JSONException: Value <?php of type java.lang.String cannot be converted to JSONArray

    Apparently, the response from the php in the server side was not the one expected. After debugging the program, i found out that the string result contains the php code as it is written and not the result. Why is this happening? Is it something wrong with the java code? my guess is that the php file is not executed and the answer returned is the php file.

    PS: the php file works fine after executing "php myFile.php" on terminal on server.

  96. vw91

    My java code:
    package com.list;

    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 nameValuePairs = new ArrayList();
    //http post
    try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(“http://10.0.2.2/receive.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
    int ct_id;
    String ct_name;
    try{
    jArray = new JSONArray(result);
    JSONObject json_data=null;
    for(int i=0;i<jArray.length();i++){
    json_data = jArray.getJSONObject(i);
    ct_id=json_data.getInt("CITY_ID");
    ct_name=json_data.getString("CITY_NAME");
    }
    }
    catch(JSONException e1){
    Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
    } catch (ParseException e1) {
    e1.printStackTrace();
    }
    }
    }

    My php code:

  97. rhood

    Hello.
    I have to implement that my android application can read data from servers in difference location and difference database.
    I am wandering in witch server I ‘ll have to put PHP file/script.
    Can anyone help me please?

    Something similar that:
    Remote DB and MySQL NOW!

    Thank you in advance.

  98. sarayu

    Hi ,

    Thanks for the blog . This was very useful . I wanted to know if it possible to send bulk data from the android activity to the php script running on the server . In your above example you only send a nameValuePair to the server and you get response from the server .

    How ever if i want to sync back a lot of data , is it possible . Can you please help me with this ?

  99. israel

    pls i need help.i tried the code above and it kept saying http://localhost connection refused but i have add the in my app what shoud i do pls

  100. frog

    Hey, i am a novice at this. How do i set up server?
    I hope for a fast response.
    Thank you

  101. tejas

    Hi bhargav,

    I have two warning that are currently giving me problems.
    int ct_id;
    String ct_name;
    can u plz help me with this.

    thnks

  102. Manoj M

    Hai Bhargav

    I wish know how to create a text message activity to send sms messages how to link my current activity to the default text messaging.

  103. tejas

    im still getting error with the code.an i cnt find th error.
    can you plz explain me ths line
    BufferedReader reader = new BufferedReader(new InputStreamReader(is,”iso-8859-1″),8);

    and should i change the http to localhost

    plz help me

    thnks

  104. Hemalatha

    I don’t know how will i print city id and name in screen . i don’t wan’t to use log.

    thanks

  105. Ankit

    Hi Bhargav,

    Thanks for the excellent tutorial. I am getting following exception in log_cat -

    04-07 11:09:31.651: E/log_tag(872): Error in http connectionandroid.os.NetworkOnMainThreadException

    Could you please suggest me where I am going wrong ? I have used http://10.0.2.2/city.php. My city.php file is in www folder and when opening from browser with http://localhost/city.php It is returning me the correct results.

    Any help is highly appreciated. Thanks in advance.

  106. Adity

    Here’s my error….followed to the code completely but still getting errors…

    04-13 10:49:52.028: W/dalvikvm(890): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)

  107. Alan

    Gracias, este es el mejor blog que he encontrado sobre Android

  108. N3sh

    Hello,

    I am getting Error in http connectionandroid.os.NetworkOnMainThreadException.
    I tried to use an AsyncTask but still couldnt managet to solve it.

    Is there any solution?
    I am trying to run basically the same example on my side, so no big loop or anything…

    Thanks

  109. Alan

    You must extends to Activity, try erasing ListActivity and replace it for Activity in ” public class city extends ListActivity { … “, then if you are on eclipse, press ” ctrl + shift + O ” for refreshing the imports.

  110. helpmepls

    i am trying to insert data to from mobile device to database…can you email me the full source code at android application?

  111. AJ

    Does not work, tried many environments…………………..

  112. Phedon Rousou

    Hello, can anyone tell me if this method can support multiple users? I am building an android application where the user can search for different data in the database. What happens if 2 android users try to search something at exactly the same time?

  113. SwordRiver57

    THANK YOU SO MUCH!

    But why this error is occurring

    — ‘View cannot be resolved to a type’ at this line ‘public void onItemClick(AdapterView parent, View view, int position, long id) {‘

  114. Wolf

    I have application for job search, it works over httppost to activate PHP function and get filtered(depends what kind of search user choose) data (JSon format) from mysql database on server.
    What I want to do now is to put one checkbox for notifications, and if user check it before click on search, to be able to get notifications in Status bar about new jobs he didn’t see at the first time, I mean when user is not using app, that application can remind user that he have new jobs in his search, for example (“You have 10 new jobs in your search”). User can receive notifications every day for example.
    And after he click on notification application will open on the page with the list of jobs he already seen + new jobs, just I want to somehow show user which jobs are new, I was thinking that maybe I can wrap the new data in a different color or something…
    Also, I want to put option if user wants to turn off notification.
    How can I do that?
    Thank you in advance,
    Wolf

  115. Walle

    I dont really know why, but i get an error. I have done everything you said, but my emulator says, Unfortunately, Tutorial has stopped

  116. Walle

    The code is working, but im not able to retrieve any cities. It only shows on the screen, No City Found ? And i have put some cities in my database

  117. anand

    hai bhargav,
    pls help..i tried your code as it is..but my emulator (2.2) shows:

    http://10.0.2.2/phpMyAdmin/php.php

    i tried localhost,127.0.0.1 instaed of 10.0.2.2 but no way.
    i use xampp for localhosting..in my browser, the output is shown clearly:

    [{"id":"55","name":"aaa","sex":"1","birthyear":"1988"}]

    used ‘Activity’ instead of ListActivity..bt same

    pls help me urgently

    no other errors are shown

  118. selva

    i have connected android with mysql using php…

    data is moving to database is successfully………

    i gave the data is “9999999999999″

    nameValuePairs.add(new BasicNameValuePair(“f3″,”9999999999″));

    i was set length is 20 for that column..

    but data is storing always as “2147483647″ in my table…

    Give some solutions for that..

    thanks to all…

  119. wishvajith

    This is wonderful tutorial and was really helpful for me to connect MS SQL db using php odbc libs. thnkz a lot :smile: :smile: :smile:

Leave a Reply

Your email address will not be published. Required fields are marked *


+ 4 = twelve

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>