apache - Why is executing this HttpGet in Android raising a NullPointerException? -


I have created a new Android project in which the code I added is the code onCreate () Method (I have also included Internet permission in the manifest):

  Override public null on @Create (bundled saved instenstate) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_http_get_test); HTTP Client Client = New DefaultHttpClient (); HttpGet Request = New HttpGet (); Try {System.out.println ("Try to Make"); URI Yuri = New URI ("http://w3mentor.com/"); Request.setURI (URI); Println ("implemented"); Client.execute (request); // This line throws exceptions System.out.println ("done!"); } Hold (exception e) {System.out.println (e.getMessage ()); In logging in, I see that the last thing printed by  try  block  blocks  was followed, after which a NullPointerException was thrown.  

I initially loose my code, but I can not see what I am doing which causes a nullionist exception.

When running in a debugger, see that the exception is actually a NetworkOnManThreadException, which is apparently when I e.getMessage () . .

07-12 02: 58: 33.9 9 7: E / Android Runtime (983): Files Exception: Main 07-12 02:58 58: 33.9 9 7: E / Android Random (983): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.whatever.http.test / com.whatever.http.test.HttpGetTest }: Java.lang.NullPointerException 07-12 02: 58: 33.997: E / AndroidRuntime (983): android.app.ActivityThread.performLaunchActivity (ActivityThread.java:1956) 07-12 02: 58: 33.9 9 7: E / Android Rendime (983): On Android. Pp.ActivityThread.handleLaunchActivity (ActivityThread.java:1981) 07-12 02:58 58: 33.997: E / AndroidRuntime (983): android.app.ActivityThread.access $ 600 (ActivityThread.java:123) on 07-12 02: 58: 33.997: E / AndroidRuntime (983): 58 :: 33.997: E / AndroidRuntime (983): android.os.Handler on android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1147) 07-12 02 . Send Message (Handler. 99) 07-12 02: 58: 33.9 9 7: E / Android Random (983): Android. Los. Looper Lope (Luor.JavaP.37) 07-12 02: 58: 33.97 7: E / Android Random (983): Android. App ActivateTrade.Mine (ActivityTrad.Java 4424) 07-12 02: 58: 33.9 9 7: E / Android Retent Man (983): at java.lang.reflect.Method.invokeNative (Basic Method) 07-12 02: 58: 33.9 9 7: E / Android Runtime (983): at java.lang.reflect.Method.invoke (method Java 0511) 07-12 02: 58: 33.9 9 7: E / Android Time (983): at com.android. Internal.os.zygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:784) 07-12 02:58 58: 33.997: E / AndroidRuntime (983): com.android.internal.os.ZygoteInit.main (ZygoteInit Java: 5 51 ) 07-12 02: 58: 33.9 9 7: E / Android Retent Man (983): Dlvic. System NetStart.main (native method) 07-12 02:58: 33.99 7: E / Android time (983): Reasons for this: Java .lang.NullPointerException 07-12 02: 58: 33.997: E / AndroidRuntime (983): on Com.android.internal.os.LoggingPrintStream.println (LoggingPrintStream.java telugu98) 07-12 02:58 58: 33.997: E / AndroidRuntime (983): 58 :: 33.997: E / AndroidRuntime (983): android.app. In Activity.performCreate (activity com.whatever.http.test.HttpGetTest.onCreate (HttpGetTest.java:33) on 07-12 02.java: 4465) 07-12 02: 58: 33.9 9 7: E / Android Random ( 983): Android. App Instrumentation. Call ActiveVector (Instrumentation. Java 0949) 07-12 02: 58: 33.9 9 7: E / Android Time (983): At android.app.ActivityThread.performLaunchActivity (ActivityThread.java1920) 07-12 02: 58: 33.9 9 7 : E / AndroidTime (983): ... 11 more

The problem is not a NullPointerException , But if you debug your application, you will know that the exception is: networkonMinethread Expression .

Most of the time, you are running your application on new SDK (Honeycomb or more), which has resulted in it being disappointed.

Any networking code, you must put in a thread. Ideally use AsyncTask for this. Check out this link:

Hope it helps.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -