I get this error on my Ice Cream Sandwich (Android 4.0) device and emulator. But the app runs perfectly on Android 2.3 emulator.
06-19 00:34:38.357: E/AndroidRuntime(535): FATAL EXCEPTION: main
06-19 00:34:38.357: E/AndroidRuntime(535): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kickinglettuce.rate_this/com.kickinglettuce.rate_this.Main}: java.lang.NullPointerException
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.os.Looper.loop(Looper.java:137)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-19 00:34:38.357: E/AndroidRuntime(535): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 00:34:38.357: E/AndroidRuntime(535): at java.lang.reflect.Method.invoke(Method.java:511)
06-19 00:34:38.357: E/AndroidRuntime(535): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-19 00:34:38.357: E/AndroidRuntime(535): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-19 00:34:38.357: E/AndroidRuntime(535): at dalvik.system.NativeStart.main(Native Method)
06-19 00:34:38.357: E/AndroidRuntime(535): Caused by: java.lang.NullPointerException
06-19 00:34:38.357: E/AndroidRuntime(535): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
06-19 00:34:38.357: E/AndroidRuntime(535): at org.json.JSONTokener.nextValue(JSONTokener.java:94)
06-19 00:34:38.357: E/AndroidRuntime(535): at org.json.JSONArray.(JSONArray.java:87)
06-19 00:34:38.357: E/AndroidRuntime(535): at org.json.JSONArray.(JSONArray.java:103)
06-19 00:34:38.357: E/AndroidRuntime(535): at com.kickinglettuce.rate_this.Main.onCreate(Main.java:81)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.Activity.performCreate(Activity.java:4465)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-19 00:34:38.357: E/AndroidRuntime(535): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-19 00:34:38.357: E/AndroidRuntime(535): ... 11 more
The start-up activity is almost identical to this:
http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/
Here is the null line in my code:
jArray = new JSONArray(result);
I wrote a blog post this morning on the same topic:
Why Does My App Crash On Ice Cream Sandwich?
The reason you are performing because you are getting a force close is because you are attempting a network connection on the UI thread. This is a potentially expensive operation and will likely block the UI thread causing lag. ICS and HoneyComb introduced stricter checks against abusing the UI thread, and now automatically force closes your app if you attempt doing so. This is why your application crashes on Android 4.0 but not on Android 2.3. You should perform the HTTP request in a separate thread of some sort (i.e. either a plain
Threador anAsyncTask).Read my blog post linked above… it goes into more detail why you should be performing such operations in a separate worker thread. You might also find this sample code helpful in getting you started.