java - Android app making 2.2 version but not compatible for 2.2+ versions -


i have app, should work in 2.2+ versions. have tested in both android devices , emulators. app working in few versions not working in higher versions, if launched app iam getting error null value. don't know why happening. according assumption "if developed app lower versions should work in other higher version", not working. please me.

here code working in 2.2, 2.3 , few higher versions. not working in 3.2 , higher. i'm getting null value

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main_geotracker);      textbox1 = (textview) findviewbyid(r.id.textinname1);     textbox2 = (textview) findviewbyid(r.id.textinname2);      connectivitymanager cm = (connectivitymanager) getsystemservice(context.connectivity_service);     networkinfo ni = cm.getactivenetworkinfo();     if (ni != null && ni.isconnected())     {         msg = "please login continue";         login();     }     else     {         msg = "sorry , network connection not available.";         message();     } }  //login------------------------------------------------------------------------------------ public void login() {     final edittext uname = new edittext(this);      final edittext upassword = new edittext(this);     dialoginterface.onclicklistener dialogclicklistener = new dialoginterface.onclicklistener()     {         // dialoginterface called while setting alertdialog buttons         public void onclick(dialoginterface dialog, int which)         {             //here can perform functions of alert dialog buttons shown              switch(which)              {                 case dialoginterface.button_positive:                     if(!uname.gettext().tostring().equals("") && !upassword.gettext().tostring().equals(""))                     {                         session_name = uname.gettext().tostring();                         session_pwd = upassword.gettext().tostring();                         try                         {                             uid = httppost(uname.gettext().tostring(), upassword.gettext().tostring(), "login.php"); //here iam getting null value.                             log.i("tag", ""+uid);                         }                         catch(jsonexception e)                         {                             // todo auto-generated catch block                             e.printstacktrace();                         }                          if(uid == null || uid.length() == 6)                         {                             msg = "either user name or password or both incorrect.";                             login();                         }                         else                         {                             toast.maketext(getapplicationcontext(), "hello " + uname.gettext().tostring() + ", have logged in..:)", toast.length_long).show();                             idlist()                         }                     }                     else                     {                         toast.maketext(getapplicationcontext(), "sorry, either user name or password or both incorrect..:(", toast.length_long).show();                         msg = "both user name , password mandatory fields.";                         login();                     }                 break;                  case dialoginterface.button_negative:                     exit();                 break;             }          }      };       alertdialog.builder builder = new alertdialog.builder(this);      linearlayout orientation = new linearlayout(this);      orientation.setorientation(1); //1 vertical orientation      uname.sethint("enter name");      upassword.sethint("enter password");      upassword.setinputtype(inputtype.type_class_text | inputtype.type_text_variation_password);      orientation.addview(uname);      orientation.addview(upassword);      builder.setview(orientation);      builder.setmessage(msg);      builder.settitle("login")      .seticon(r.drawable.ic_launcher)      .setpositivebutton("submit", dialogclicklistener)      .setnegativebutton("exit app", dialogclicklistener).show(); }  public string httppost(string param1, string param2, string file) throws jsonexception {         try       {         string data = urlencoder.encode("param1", "utf-8") + "=" + urlencoder.encode(param1, "utf-8");         data += "&" + urlencoder.encode("param2", "utf-8") + "=" + urlencoder.encode(param2, "utf-8");          // send data         url url = new url("http://192.168.1.12/geotracker/android/"+file);         urlconnection conn = url.openconnection();         conn.setdooutput(true);         outputstreamwriter wr = new outputstreamwriter(conn.getoutputstream());         wr.write(data);         wr.flush();          // response         bufferedreader rd = new bufferedreader(new inputstreamreader(conn.getinputstream()));         the_string_response = rd.readline();         wr.close();         rd.close();     }     catch (exception e)     {     }     textbox1.settext("");     textbox2.settext("");      return the_string_response; } 

here log cat,

`05-21 19:12:50.610: d/dalvikvm(4100): late-enabling checkjni  05-21 19:12:50.850: e/phonepolicy(4100): not preload class phone policy: com.android.internal.policy.impl.phonewindow$contextmenucallback  05-21 19:12:50.970: d/textlayoutcache(4100): using debug level: 0 - debug enabled: 0  05-21 19:12:51.160: i/dalvikvm(4100): threadid=1: recursive native library load attempt (/system/lib/libwebcore.so)  05-21 19:12:51.160: d/dalvikvm(4100): no jni_onload found in /system/lib/libchromium_net.so 0x0, skipping init  05-21 19:12:51.220: d/dalvikvm(4100): gc_concurrent freed 134k, 4% free 5078k/5255k, paused 1ms+1ms  05-21 19:12:51.750: d/libegl(4100): loaded /system/lib/egl/libegl_mali.so  05-21 19:12:51.760: d/libegl(4100): loaded /system/lib/egl/libglesv1_cm_mali.so  05-21 19:12:51.770: d/libegl(4100): loaded /system/lib/egl/libglesv2_mali.so  05-21 19:12:51.820: d/openglrenderer(4100): enabling debug mode 0  05-21 19:12:59.690: d/dalvikvm(4100): gc_concurrent freed 159k, 5% free 5329k/5575k,  paused 2ms+4ms`  05-21 19:13:11.500: i/tag(4100): null 

please me, in advance...

on devices high enough api level system prevents doing network operations (http post etc...) in main thread. if further in logcat (set verbose) somewhere you'll find network_on_main_thread_exception in there.

that looks doing. work fine on lower api levels because platform didn't restrict (though still bad idea)

to fix need move network operation off of main thread. consider using asynctask


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -