Android ListView not poulating with json datas -


i want populate listview json values. i'm able json values, dont know problem is.

in logcat shows nullpointerexception , unfortunately activity stops.

suggesstion plz......

my java

  public class certify_absent_list extends activity {     private static listview listview;     private static list<string> list;     private string teachername,date;       @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         //setcontentview(r.layout.);         listview=(listview) findviewbyid(r.id.listview1);          list=new arraylist<string>();         teachername=getintent().getextras().getstring("teachername");         date=getintent().getextras().getstring("today");         new absent_list_bg_task().execute();     }     private class absent_list_bg_task extends asynctask<string,void,string>     {           protected string doinbackground(string... params) {                 try{                               string link="http://192.168.1.11:81/schoolapp/absent_list.php";                              string data  = urlencoder.encode("teachername", "utf-8")                              + "=" + urlencoder.encode("teacher1", "utf-8");                               data += "&" + urlencoder.encode("date", "utf-8")                              + "=" + urlencoder.encode("2013-01-01", "utf-8");                            /* string data  = urlencoder.encode("teachername ", "utf-8")                              + "=" + urlencoder.encode("teacher1", "utf-8");                             data += "&" + urlencoder.encode("date", "utf-8")                              + "=" + urlencoder.encode("2013-01-01", "utf-8");*/                             url url = new url(link);                             urlconnection conn = url.openconnection();                              conn.setdooutput(true);                              outputstreamwriter wr = new outputstreamwriter                             (conn.getoutputstream());                              wr.write( data );                              wr.flush();                              bufferedreader reader = new bufferedreader                             (new inputstreamreader(conn.getinputstream()));                              stringbuilder sb = new stringbuilder();                             string line = null;                             // read server response                             while((line = reader.readline()) != null)                             {                                sb.append(line);                                break;                             }                            return sb.tostring();                           }catch(exception e){                             return new string("exception: " + e.getmessage());                          }                 }                    @override                 protected void onpostexecute(string result)                    {                         arrayadapter<string> adapter = null;                         jsonarray arr = null;                         jsonobject obj = null;                           toast.maketext(certify_absent_list.this,result, toast.length_long).show();                          if(result.equals("wrong"))                          {                           toast.maketext(certify_absent_list.this,"invalid username or password.", toast.length_long).show();                         }                         else                        {                             toast.maketext(certify_absent_list.this,result, toast.length_long).show();                             try {                                 arr=new jsonarray(result);                             } catch (jsonexception e) {                                 // todo auto-generated catch block                                 e.printstacktrace();                             }                              for(int i=0;i<arr.length();i++)                             {                                 try {                                     obj=arr.getjsonobject(i);                                 } catch (jsonexception e) {                                     // todo auto-generated catch block                                     e.printstacktrace();                                 }                                  try {                                     list.add(obj.getstring("childname"));                                 } catch (jsonexception e) {                                     // todo auto-generated catch block                                     e.printstacktrace();                                 }                                 toast.maketext(certify_absent_list.this,list.get(i).tostring(), toast.length_long).show();                              }                           }                        adapter=new arrayadapter<string>(certify_absent_list.this, android.r.layout.simple_list_item_1, list);                        //adapter.notifydatasetchanged();                        listview.setadapter(adapter);       }     }     } 

json output

[{"childname":""},{"childname":"childname1"},{"childname":"childname7"},{"childname":"childname11"},{"childname":"childname11"},{"childname":"childname11"}] 

logcat:

    03-21 07:35:29.128: e/androidruntime(1443): java.lang.nullpointerexception     03-21 07:35:29.128: e/androidruntime(1443):     @ com.example.certify_teacher_login.certify_absent_list$absent_list_bg_task.onpostexecute(certify_absent_list.java:121) 03-21 07:35:29.128: e/androidruntime(1443):     @ com.example.certify_teacher_login.certify_absent_list$absent_list_bg_task.onpostexecute(certify_absent_list.java:1) 03-21 07:35:29.128: e/androidruntime(1443):     @ android.os.asynctask.finish(asynctask.java:632) 03-21 07:35:29.128: e/androidruntime(1443):     @ android.os.asynctask.access$600(asynctask.java:177) 03-21 07:35:29.128: e/androidruntime(1443):     @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645) 03-21 07:35:29.128: e/androidruntime(1443):     @ android.os.handler.dispatchmessage(handler.java:102) 03-21 07:35:29.128: e/androidruntime(1443):     @ android.os.looper.loop(looper.java:137) 03-21 07:35:29.128: e/androidruntime(1443):     @ android.app.activitythread.main(activitythread.java:4998) 03-21 07:35:29.128: e/androidruntime(1443):     @ java.lang.reflect.method.invokenative(native method) 03-21 07:35:29.128: e/androidruntime(1443):     @ java.lang.reflect.method.invoke(method.java:515) 03-21 07:35:29.128: e/androidruntime(1443):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:777) 03-21 07:35:29.128: e/androidruntime(1443):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:593) 03-21 07:35:29.128: e/androidruntime(1443):     @ dalvik.system.nativestart.main(native method) 

   //setcontentview(r.layout.);  

why line commented ? don't extend listactivity or use fragments either. unless thats typing mistake not going work !


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -