Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update old android project

I am following this tutorial and I can make it work just fine, but when I try to update the UI to fit the new Holo.Light in android 4.2 the app crashes at launch, and I don't know why.

I have been searching for a way to update the UI but I could not get it to work.

I wonder if anybody could help me? tell me how? Give me a link that you know would work? or even do it yourself?

i get this error log:

11-20 09:50:39.523: I/dalvikvm(1460): threadid=3: reacting to signal 3
11-20 09:50:39.682: I/dalvikvm(1460): Wrote stack traces to '/data/anr/traces.txt'
11-20 09:50:39.892: I/dalvikvm(1460): threadid=3: reacting to signal 3
11-20 09:50:40.003: I/dalvikvm(1460): Wrote stack traces to '/data/anr/traces.txt'
11-20 09:50:40.102: D/AndroidRuntime(1460): Shutting down VM
11-20 09:50:40.102: W/dalvikvm(1460): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-20 09:50:40.132: E/AndroidRuntime(1460): FATAL EXCEPTION: main
11-20 09:50:40.132: E/AndroidRuntime(1460): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.jsonparsing/com.androidhive.jsonparsing.AndroidJSONParsingActivity}: android.os.NetworkOnMainThreadException
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.os.Looper.loop(Looper.java:137)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at java.lang.reflect.Method.invokeNative(Native Method)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at java.lang.reflect.Method.invoke(Method.java:511)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at dalvik.system.NativeStart.main(Native Method)
11-20 09:50:40.132: E/AndroidRuntime(1460): Caused by: android.os.NetworkOnMainThreadException
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at com.androidhive.jsonparsing.JSONParser.getJSONFromUrl(JSONParser.java:38)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at com.androidhive.jsonparsing.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:53)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.Activity.performCreate(Activity.java:4465)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-20 09:50:40.132: E/AndroidRuntime(1460):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
11-20 09:50:40.132: E/AndroidRuntime(1460):     ... 11 more
11-20 09:50:40.392: I/dalvikvm(1460): threadid=3: reacting to signal 3
11-20 09:50:40.412: I/dalvikvm(1460): Wrote stack traces to '/data/anr/traces.txt'
11-20 09:50:40.791: I/dalvikvm(1460): threadid=3: reacting to signal 3
11-20 09:50:40.962: I/dalvikvm(1460): Wrote stack traces to '/data/anr/traces.txt'
like image 564
magnuskahr Avatar asked Jan 25 '26 20:01

magnuskahr


1 Answers

You are making a network call on the main thread. This is not allowed on Android 4.2, and is a really bad idea on earlier versions which do permit this. I have blogged about various mechanisms for moving network and other heavy calls off the main thread at http://blog.stylingandroid.com/archives/833.

Without seeing your code, I cannot begin to suggest which approach is the right one for you to use, but hopefully the information in my articles will help you in deciding upon the correct approach.

like image 102
Mark Allison Avatar answered Jan 27 '26 10:01

Mark Allison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!