Excuse me if I don't know that I am asking a stupid question or not as a beginner.
I am retrieving values from mysql database and trying to display it in a TextView.
My database field name is "entry" and value is "444". Please tell me how I can display this value in my textview.
Home.java:
public class Home extends Activity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_home);
tv = (TextView) findViewById(R.id.textView1);
getData();
}
public void getData(){
String result="";
InputStream isr=null;
try{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://xxxxxx/get_data.php");
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
} catch(Exception e){
Log.e("log_tag","Error in http connection"+e.toString());
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(
isr, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();
result= sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try{
JSONArray jArray=new JSONArray(result);
JSONObject json=jArray.getJSONObject(0);
String s= json.getString("entry");
tv.setText(s);
} catch(Exception e){
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
}
Here is my logcat:
D/dalvikvm(276): GC_FOR_MALLOC freed 3041 objects / 204440 bytes in 283ms
W/SingleClientConnManager(276): Invalid use of SingleClientConnManager: connection still allocated.
W/SingleClientConnManager(276): Make sure to release the connection before allocating another one.
D/dalvikvm(276): GC_FOR_MALLOC freed 707 objects / 47856 bytes in 55ms
I/System.out(276): Response : User Found
E/log_tag(276): Error parsing data java.lang.NullPointerException