Calling autoFocus() from parent Activity returns NPE - android

I have instantiated a fragment type that extends CameraFragment (and implements TabListener), and I am trying to call the autoFocus() from the the parent Activity. Calling autoFocus() from the fragment that extends CameraFragment works fine, but calling it from the parent Activity results in an NPE. I am listening for a onKeyDown() event in the main Activity, which works as expected as per the logcat. Here is my NPE trace:
09-10 10:00:16.410: D/app(5283): onKeyDown: 80
09-10 10:00:16.415: D/AndroidRuntime(5283): Shutting down VM
09-10 10:00:16.415: W/dalvikvm(5283): threadid=1: thread exiting with uncaught exception (group=0x40f7b2a0)
09-10 10:00:16.425: E/AndroidRuntime(5283): FATAL EXCEPTION: main
09-10 10:00:16.425: E/AndroidRuntime(5283): java.lang.NullPointerException
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.commonsware.cwac.camera.CameraFragment.autoFocus(CameraFragment.java:96)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.me.app.appCameraFragment.callAutoFocus(cameraFragment.java:232)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.me.app.MainTabActivity.onKeyDown(MainTabActivity.java:264)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.KeyEvent.dispatch(KeyEvent.java:2705)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.app.Activity.dispatchKeyEvent(Activity.java:2423)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2019)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3851)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3799)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2934)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.os.Looper.loop(Looper.java:137)
09-10 10:00:16.425: E/AndroidRuntime(5283): at android.app.ActivityThread.main(ActivityThread.java:4921)
09-10 10:00:16.425: E/AndroidRuntime(5283): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 10:00:16.425: E/AndroidRuntime(5283): at java.lang.reflect.Method.invoke(Method.java:511)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
09-10 10:00:16.425: E/AndroidRuntime(5283): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
09-10 10:00:16.425: E/AndroidRuntime(5283): at dalvik.system.NativeStart.main(Native Method)

I'm not sure what version of the code you are working on, but line 96 is a closing brace in the current CameraFragment.
The only way autoFocus() can crash with a NullPointerException is if cameraView is null, and the only way cameraView should be null is if onCreateView() has not yet been called. You need the fragment to be visible and fully created before you request auto-focus.

Related

AVD crashes saying 'Unfortunately, libcocos2dx has crashed'

I just loaded my app created by cocos2dx-3.10 and when I open with it an AVD (again I haven't done any modifications to the app) the app crashes and gives the error: Unfortunately, libcocos2dx has crashed.
here is what I get in my android Monitor:
03-05 18:34:56.668 1435-1435/? D/dalvikvm: Not late-enabling CheckJNI (already on)
03-05 18:34:56.989 1435-1435/com.trying.name E/Trace: error opening trace file: No such file or directory (2)
03-05 18:34:57.419 1435-1435/com.trying.name D/AndroidRuntime: Shutting down VM
03-05 18:34:57.419 1435-1435/com.trying.name W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb2f2b288)
03-05 18:34:57.518 1435-1435/com.trying.name E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-05 18:35:11.559 1435-1435/? I/Process: Sending signal. PID: 1435 SIG: 9

Issue with If-statement in getting data from MySQL

I'm trying to populate ListView with data from MySQL. I used this tutorial.
Here I want to get data only when rating is equal to 3. I try this, but it doesn't work. I don't really understand how JSON works. Probably I can't get the same value from the same column. Then, I try creating a new column with the same values like rating, but it doesn't work too. The emulator started, but then app crashed.
First attempt
try {
// convert json string to json array
JSONArray aJson = new JSONArray(sJson);
// create apps list
String rating = "3";
List<Application> apps = new ArrayList<Application>();
for(int i=0; i<aJson.length(); i++) {
JSONObject json = aJson.getJSONObject(i);
Application app = new Application();
String rating_of_app = json.getString("rating");
if ((rating_of_app).equals(rating)) {
app.setTitle(json.getString("app_title"));
app.setTotalDl(Long.parseLong(json.getString("total_dl")));
app.setRating(Integer.parseInt(json.getString("rating")));
app.setIcon(json.getString("icon"));}
// add the app to apps list
apps.add(app);
}
Second attempt with new column
try {
// convert json string to json array
JSONArray aJson = new JSONArray(sJson);
// create apps list
String rating = "3";
List<Application> apps = new ArrayList<Application>();
for(int i=0; i<aJson.length(); i++) {
JSONObject json = aJson.getJSONObject(i);
Application app = new Application();
String rating_of_app = json.getString("rating_for_if");
if ((rating_of_app).equals(rating)) {
app.setTitle(json.getString("app_title"));
app.setTotalDl(Long.parseLong(json.getString("total_dl")));
app.setRating(Integer.parseInt(json.getString("rating")));
app.setIcon(json.getString("icon"));}
// add the app to apps list
apps.add(app);
}
When I donĀ“t put there if statement it works great but it is useless for me.
Here it is for the first Attempt:
09-10 05:15:44.970: D/dalvikvm(837): GC_FOR_ALLOC freed 50K, 5% free 2948K/3084K, paused 277ms, total 278ms
09-10 05:15:44.970: I/dalvikvm-heap(837): Grow heap (frag case) to 3.565MB for 635812-byte allocation
09-10 05:15:45.150: D/dalvikvm(837): GC_FOR_ALLOC freed 2K, 4% free 3566K/3708K, paused 96ms, total 164ms
09-10 05:15:46.670: I/Choreographer(837): Skipped 67 frames! The application may be doing too much work on its main thread.
09-10 05:15:47.580: I/Choreographer(837): Skipped 159 frames! The application may be doing too much work on its main thread.
09-10 05:15:47.890: D/gralloc_goldfish(837): Emulator without GPU emulation detected.
09-10 05:15:48.160: I/Choreographer(837): Skipped 52 frames! The application may be doing too much work on its main thread.
09-10 05:15:48.460: I/Choreographer(837): Skipped 48 frames! The application may be doing too much work on its main thread.
09-10 05:15:48.640: I/Choreographer(837): Skipped 34 frames! The application may be doing too much work on its main thread.
09-10 05:15:50.350: I/Choreographer(837): Skipped 37 frames! The application may be doing too much work on its main thread.
09-10 05:15:50.690: I/Choreographer(837): Skipped 32 frames! The application may be doing too much work on its main thread.
09-10 05:15:51.150: I/Choreographer(837): Skipped 45 frames! The application may be doing too much work on its main thread.
09-10 05:15:55.190: I/Choreographer(837): Skipped 31 frames! The application may be doing too much work on its main thread.
09-10 05:15:56.040: I/Choreographer(837): Skipped 45 frames! The application may be doing too much work on its main thread.
09-10 05:15:56.470: I/Choreographer(837): Skipped 30 frames! The application may be doing too much work on its main thread.
09-10 05:15:58.470: I/Choreographer(837): Skipped 45 frames! The application may be doing too much work on its main thread.
09-10 05:16:00.560: I/Choreographer(837): Skipped 52 frames! The application may be doing too much work on its main thread.
09-10 05:16:00.710: I/Choreographer(837): Skipped 36 frames! The application may be doing too much work on its main thread.
09-10 05:16:00.960: I/Choreographer(837): Skipped 36 frames! The application may be doing too much work on its main thread.
09-10 05:16:01.290: I/Choreographer(837): Skipped 33 frames! The application may be doing too much work on its main thread.
09-10 05:16:02.310: I/Choreographer(837): Skipped 43 frames! The application may be doing too much work on its main thread.
09-10 05:16:02.730: D/dalvikvm(837): GC_FOR_ALLOC freed 227K, 8% free 3852K/4164K, paused 79ms, total 84ms
09-10 05:16:02.920: I/Choreographer(837): Skipped 111 frames! The application may be doing too much work on its main thread.
09-10 05:16:03.030: W/ResourceType(837): No package identifier when getting value for resource number 0x00000000
09-10 05:16:03.040: D/AndroidRuntime(837): Shutting down VM
09-10 05:16:03.040: W/dalvikvm(837): threadid=1: thread exiting with uncaught exception (group=0xb3a16ba8)
09-10 05:16:03.070: E/AndroidRuntime(837): FATAL EXCEPTION: main
09-10 05:16:03.070: E/AndroidRuntime(837): Process: com.sj.jsondemo, PID: 837
09-10 05:16:03.070: E/AndroidRuntime(837): android.content.res.Resources$NotFoundException: Resource ID #0x0
09-10 05:16:03.070: E/AndroidRuntime(837): at android.content.res.Resources.getValue(Resources.java:1123)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.content.res.Resources.getDrawable(Resources.java:698)
09-10 05:16:03.070: E/AndroidRuntime(837): at com.sj.jsondemo.ApplicationAdapter.getView(ApplicationAdapter.java:49)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.ListView.onMeasure(ListView.java:1175)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.View.measure(View.java:16497)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.View.measure(View.java:16497)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.View.measure(View.java:16497)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:16:03.070: E/AndroidRuntime(837): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.View.measure(View.java:16497)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-10 05:16:03.070: E/AndroidRuntime(837): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.View.measure(View.java:16497)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.Choreographer.doFrame(Choreographer.java:544)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.os.Handler.handleCallback(Handler.java:733)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.os.Handler.dispatchMessage(Handler.java:95)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.os.Looper.loop(Looper.java:136)
09-10 05:16:03.070: E/AndroidRuntime(837): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-10 05:16:03.070: E/AndroidRuntime(837): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 05:16:03.070: E/AndroidRuntime(837): at java.lang.reflect.Method.invoke(Method.java:515)
09-10 05:16:03.070: E/AndroidRuntime(837): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-10 05:16:03.070: E/AndroidRuntime(837): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-10 05:16:03.070: E/AndroidRuntime(837): at dalvik.system.NativeStart.main(Native Method)
09-10 05:18:03.017: I/Process(837): Sending signal. PID: 837 SIG: 9
09-10 05:18:09.827: D/dalvikvm(1109): GC_FOR_ALLOC freed 47K, 5% free 2948K/3084K, paused 40ms, total 42ms
09-10 05:18:09.827: I/dalvikvm-heap(1109): Grow heap (frag case) to 3.565MB for 635812-byte allocation
09-10 05:18:09.887: D/dalvikvm(1109): GC_FOR_ALLOC freed 2K, 4% free 3566K/3708K, paused 54ms, total 54ms
09-10 05:18:10.417: I/Choreographer(1109): Skipped 53 frames! The application may be doing too much work on its main thread.
09-10 05:18:10.437: D/gralloc_goldfish(1109): Emulator without GPU emulation detected.
09-10 05:18:10.627: I/Choreographer(1109): Skipped 42 frames! The application may be doing too much work on its main thread.
09-10 05:18:11.317: I/Choreographer(1109): Skipped 74 frames! The application may be doing too much work on its main thread.
09-10 05:18:12.397: I/Choreographer(1109): Skipped 40 frames! The application may be doing too much work on its main thread.
09-10 05:18:13.217: I/Choreographer(1109): Skipped 38 frames! The application may be doing too much work on its main thread.
09-10 05:18:13.577: I/Choreographer(1109): Skipped 34 frames! The application may be doing too much work on its main thread.
09-10 05:18:14.157: I/Choreographer(1109): Skipped 39 frames! The application may be doing too much work on its main thread.
09-10 05:18:17.097: D/dalvikvm(1109): GC_FOR_ALLOC freed 225K, 8% free 3855K/4164K, paused 33ms, total 37ms
09-10 05:18:17.187: I/Choreographer(1109): Skipped 66 frames! The application may be doing too much work on its main thread.
09-10 05:18:17.307: W/ResourceType(1109): No package identifier when getting value for resource number 0x00000000
09-10 05:18:17.307: D/AndroidRuntime(1109): Shutting down VM
09-10 05:18:17.317: W/dalvikvm(1109): threadid=1: thread exiting with uncaught exception (group=0xb3a16ba8)
09-10 05:18:17.447: E/AndroidRuntime(1109): FATAL EXCEPTION: main
09-10 05:18:17.447: E/AndroidRuntime(1109): Process: com.sj.jsondemo, PID: 1109
09-10 05:18:17.447: E/AndroidRuntime(1109): android.content.res.Resources$NotFoundException: Resource ID #0x0
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.content.res.Resources.getValue(Resources.java:1123)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.content.res.Resources.getDrawable(Resources.java:698)
09-10 05:18:17.447: E/AndroidRuntime(1109): at com.sj.jsondemo.ApplicationAdapter.getView(ApplicationAdapter.java:49)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.ListView.onMeasure(ListView.java:1175)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.View.measure(View.java:16497)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.View.measure(View.java:16497)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.View.measure(View.java:16497)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:18:17.447: E/AndroidRuntime(1109): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.View.measure(View.java:16497)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-10 05:18:17.447: E/AndroidRuntime(1109): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.View.measure(View.java:16497)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.Choreographer.doFrame(Choreographer.java:544)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.os.Handler.handleCallback(Handler.java:733)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.os.Handler.dispatchMessage(Handler.java:95)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.os.Looper.loop(Looper.java:136)
09-10 05:18:17.447: E/AndroidRuntime(1109): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-10 05:18:17.447: E/AndroidRuntime(1109): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 05:18:17.447: E/AndroidRuntime(1109): at java.lang.reflect.Method.invoke(Method.java:515)
09-10 05:18:17.447: E/AndroidRuntime(1109): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-10 05:18:17.447: E/AndroidRuntime(1109): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-10 05:18:17.447: E/AndroidRuntime(1109): at dalvik.system.NativeStart.main(Native Method)
and for the second attempt with new column:
09-10 05:25:34.410: D/dalvikvm(828): GC_FOR_ALLOC freed 47K, 5% free 2948K/3076K, paused 115ms, total 117ms
09-10 05:25:34.410: I/dalvikvm-heap(828): Grow heap (frag case) to 3.557MB for 635812-byte allocation
09-10 05:25:34.490: D/dalvikvm(828): GC_FOR_ALLOC freed 2K, 4% free 3566K/3700K, paused 70ms, total 71ms
09-10 05:25:35.040: I/Choreographer(828): Skipped 46 frames! The application may be doing too much work on its main thread.
09-10 05:25:35.110: D/gralloc_goldfish(828): Emulator without GPU emulation detected.
09-10 05:25:35.280: I/Choreographer(828): Skipped 39 frames! The application may be doing too much work on its main thread.
09-10 05:25:36.000: I/Choreographer(828): Skipped 155 frames! The application may be doing too much work on its main thread.
09-10 05:25:38.910: I/Choreographer(828): Skipped 32 frames! The application may be doing too much work on its main thread.
09-10 05:25:39.410: I/Choreographer(828): Skipped 30 frames! The application may be doing too much work on its main thread.
09-10 05:25:42.960: I/Choreographer(828): Skipped 36 frames! The application may be doing too much work on its main thread.
09-10 05:25:43.280: D/dalvikvm(828): GC_FOR_ALLOC freed 225K, 8% free 3855K/4156K, paused 70ms, total 73ms
09-10 05:25:43.540: I/Choreographer(828): Skipped 148 frames! The application may be doing too much work on its main thread.
09-10 05:25:43.720: W/ResourceType(828): No package identifier when getting value for resource number 0x00000000
09-10 05:25:43.720: D/AndroidRuntime(828): Shutting down VM
09-10 05:25:43.720: W/dalvikvm(828): threadid=1: thread exiting with uncaught exception (group=0xb3affba8)
09-10 05:25:43.880: E/AndroidRuntime(828): FATAL EXCEPTION: main
09-10 05:25:43.880: E/AndroidRuntime(828): Process: com.sj.jsondemo, PID: 828
09-10 05:25:43.880: E/AndroidRuntime(828): android.content.res.Resources$NotFoundException: Resource ID #0x0
09-10 05:25:43.880: E/AndroidRuntime(828): at android.content.res.Resources.getValue(Resources.java:1123)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.content.res.Resources.getDrawable(Resources.java:698)
09-10 05:25:43.880: E/AndroidRuntime(828): at com.sj.jsondemo.ApplicationAdapter.getView(ApplicationAdapter.java:49)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.ListView.onMeasure(ListView.java:1175)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.View.measure(View.java:16497)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.View.measure(View.java:16497)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.View.measure(View.java:16497)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:25:43.880: E/AndroidRuntime(828): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.View.measure(View.java:16497)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-10 05:25:43.880: E/AndroidRuntime(828): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.View.measure(View.java:16497)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.Choreographer.doFrame(Choreographer.java:544)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.os.Handler.handleCallback(Handler.java:733)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.os.Handler.dispatchMessage(Handler.java:95)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.os.Looper.loop(Looper.java:136)
09-10 05:25:43.880: E/AndroidRuntime(828): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-10 05:25:43.880: E/AndroidRuntime(828): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 05:25:43.880: E/AndroidRuntime(828): at java.lang.reflect.Method.invoke(Method.java:515)
09-10 05:25:43.880: E/AndroidRuntime(828): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-10 05:25:43.880: E/AndroidRuntime(828): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-10 05:25:43.880: E/AndroidRuntime(828): at dalvik.system.NativeStart.main(Native Method)

Problems with executing a method with asynctask from the main activity

So, I have an app which uses the Viewpager and swiping. I got 3 fragments which contains a listview, and a custom adapter to set the rows.
In each fragment, I have a method to call the asynctask and fetch the JSON. I run this method in the onActivityCreated.
When I start the app, everything is working fine, the progressdialog shows, and all the list's are being set with the correct data.
The problem is that i want to be able to refresh all the lists when click the refresh-button in the actionbar (to check for new tweets).
The only way I've been able to use the refreshbutton is when I use the onOptionsItemSelected() in the MainActivity.
So I'm thinking, I can just call the methods who then again calls the asynctask.
case R.id.menu_refresh:
MSFTHost host = new MSFTHost();
host.getTweets();
...
But when I click the button, the whole thing force closes:
02-05 21:46:57.959: W/dalvikvm(15292): threadid=1: thread exiting with uncaught exception (group=0x40d5a930)02-05 21:46:58.045:
E/AndroidRuntime(15292): FATAL EXCEPTION: main
02-05 21:46:58.045: E/AndroidRuntime(15292): java.lang.NullPointerException
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.sandan.HostingNorge.MSFTHost$DownloadWebPageTask.onPostExecute(MSFTHost.java:95)
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.sandan.HostingNorge.MSFTHost$DownloadWebPageTask.onPostExecute(MSFTHost.java:1)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.AsyncTask.finish(AsyncTask.java:631)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.AsyncTask.access$600(AsyncTask.java:177)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.os.Looper.loop(Looper.java:137)
02-05 21:46:58.045: E/AndroidRuntime(15292): at android.app.ActivityThread.main(ActivityThread.java:5202)
02-05 21:46:58.045: E/AndroidRuntime(15292): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 21:46:58.045: E/AndroidRuntime(15292): at java.lang.reflect.Method.invoke(Method.java:511)
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
02-05 21:46:58.045: E/AndroidRuntime(15292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
02-05 21:46:58.045: E/AndroidRuntime(15292): at dalvik.system.NativeStart.main(Native Method)
the line 95 contains this:
listItems.add(new GetListItems(oneObject.getString("text"),oneObject.getString("created_at"),obj
.getString("profile_image_url"), obj
.getString("screen_name")));
I tried clearing listItems, but it didn't have any effect.
Any help please?
Edit:
If I was unclear, I want to get the JSON again and show in the list, just like on the first run.

App runs fine on phones, crashes on tablets

My app runs fine on phone crashes on start up on tablets. It runs fine on my phone running 2.3.7 and my sister's phone running 4.0.3. But it crashes on my 10.1" tablet running 4.0.4. I tried it on a Nexus 7 AVD running 4.2 and it crashes there too.
This is the Log
12-26 23:11:55.350: E/Trace(845): error opening trace file: No such file or directory (2)
12-26 23:11:55.350: W/Trace(845): Unexpected value from nativeGetEnabledTags: 0
12-26 23:11:55.350: W/Trace(845): Unexpected value from nativeGetEnabledTags: 0
12-26 23:11:55.350: W/Trace(845): Unexpected value from nativeGetEnabledTags: 0
12-26 23:11:55.560: W/Trace(845): Unexpected value from nativeGetEnabledTags: 0
12-26 23:11:55.560: W/Trace(845): Unexpected value from nativeGetEnabledTags: 0
12-26 23:11:56.741: D/dalvikvm(845): GC_CONCURRENT freed 217K, 12% free 2635K/2984K, paused 70ms+14ms, total 139ms
12-26 23:11:56.751: D/dalvikvm(845): WAIT_FOR_CONCURRENT_GC blocked 4ms
12-26 23:11:56.813: D/dalvikvm(845): GC_FOR_ALLOC freed 68K, 14% free 2666K/3084K, paused 52ms, total 53ms
12-26 23:11:56.821: I/dalvikvm-heap(845): Grow heap (frag case) to 3.333MB for 635812-byte allocation
12-26 23:11:56.881: D/dalvikvm(845): GC_FOR_ALLOC freed <1K, 12% free 3286K/3708K, paused 57ms, total 57ms
12-26 23:11:56.931: D/dalvikvm(845): GC_CONCURRENT freed <1K, 12% free 3287K/3708K, paused 9ms+3ms, total 52ms
12-26 23:11:56.931: D/dalvikvm(845): WAIT_FOR_CONCURRENT_GC blocked 12ms
12-26 23:11:56.931: I/dalvikvm-heap(845): Grow heap (frag case) to 3.811MB for 500416-byte allocation
12-26 23:11:57.011: D/dalvikvm(845): GC_FOR_ALLOC freed <1K, 11% free 3775K/4200K, paused 49ms, total 49ms
12-26 23:11:57.223: D/AndroidRuntime(845): Shutting down VM
12-26 23:11:57.223: W/dalvikvm(845): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-26 23:11:57.231: E/AndroidRuntime(845): FATAL EXCEPTION: main
12-26 23:11:57.231: E/AndroidRuntime(845): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brandsonicinc.brandsonic.web.mobile/com.brandsonicinc.brandsonic.web.mobile.MainActivity}: java.lang.NullPointerException
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.os.Looper.loop(Looper.java:137)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-26 23:11:57.231: E/AndroidRuntime(845): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 23:11:57.231: E/AndroidRuntime(845): at java.lang.reflect.Method.invoke(Method.java:511)
12-26 23:11:57.231: E/AndroidRuntime(845): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-26 23:11:57.231: E/AndroidRuntime(845): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-26 23:11:57.231: E/AndroidRuntime(845): at dalvik.system.NativeStart.main(Native Method)
12-26 23:11:57.231: E/AndroidRuntime(845): Caused by: java.lang.NullPointerException
12-26 23:11:57.231: E/AndroidRuntime(845): at com.brandsonicinc.brandsonic.web.mobile.MainActivity.onCreate(MainActivity.java:84)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.Activity.performCreate(Activity.java:5104)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-26 23:11:57.231: E/AndroidRuntime(845): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-26 23:11:57.231: E/AndroidRuntime(845): ... 11 more
12-26 23:12:02.487: W/chromium(845): external/chromium/net/disk_cache/backend_impl.cc:1835: [1226/231202:WARNING:backend_impl.cc(1835)] Destroying invalid entry.
12-26 23:12:02.500: E/chromium(845): external/chromium/net/disk_cache/backend_impl.cc:1107: [1226/231202:ERROR:backend_impl.cc(1107)] Critical error found -8
12-26 23:12:02.820: W/chromium(845): external/chromium/net/disk_cache/storage_block-inl.h:119: [1226/231202:WARNING:storage_block-inl.h(119)] Failed data load.
12-26 23:12:02.820: W/chromium(845): external/chromium/net/disk_cache/storage_block-inl.h:119: [1226/231202:WARNING:storage_block-inl.h(119)] Failed data load.
12-26 23:12:02.840: W/chromium(845): external/chromium/net/disk_cache/storage_block-inl.h:119: [1226/231202:WARNING:storage_block-inl.h(119)] Failed data load.
12-26 23:12:02.881: W/chromium(845): external/chromium/net/disk_cache/storage_block-inl.h:119: [1226/231202:WARNING:storage_block-inl.h(119)] Failed data load.
12-26 23:12:02.966: E/chromium(845): external/chromium/net/disk_cache/entry_impl.cc:904: [1226/231202:ERROR:entry_impl.cc(904)] Failed to save user data
12-26 23:12:02.971: E/chromium(845): external/chromium/net/disk_cache/entry_impl.cc:904: [1226/231202:ERROR:entry_impl.cc(904)] Failed to save user data
12-26 23:12:04.361: I/Process(845): Sending signal. PID: 845 SIG: 9
Please help this is very frustrating. It used to run fine on tablets. Could it have something to do with the layouts?
try to put all your xml files in layout folder and no need to remove it from other if it already there.
If xml files are in folders like layout-sw600dp then the device will fail to load the specified xml file if screen width is less than 600dp. this is just example in your case it may be different
I have read your log, there is a bug on finding directory, have you use some directory method, to retrieve file from a particular location, tablet have internal storage instead of sd card might be problem in that.
But I can better understand if you post the code.

Google Contacts Data API on Android not working?

I try to use Google Contacts Data API on Android and more specifically the ContactsService class but the application crash as soon as I try to instantiate ContactsService class.
I do not have this problem with a normal Java application.
For example, below code is working fine
public class TestJava {
public static void main(String[] args) {
ContactsService myService = new ContactsService("TestApp");
System.out.println("OK");
}
}
However, below Android app crashes (I put the permission for Internet in the manifest)
public class TestAndroidActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContactsService myService = new ContactsService("TestApp");
System.out.println("OK");
}
}
Does anyone know if Google Contacts Data API is working on Android?
Did I miss a permission in the manifest?
Thanks in advance.
Edit:
I used two projects in Eclipse to test above code: a Java project and an Android project.
Both projects share the same libraries and only the Android project is crashing.
Here the error message:
09-10 12:12:43.928: INFO/AndroidRuntime(326): NOTE: attach of thread 'Binder Thread #3' failed
09-10 12:12:44.409: WARN/dalvikvm(332): Unable to resolve superclass of Lcom/google/gdata/client/contacts/ContactsService; (1133)
09-10 12:12:44.459: WARN/dalvikvm(332): Link of class 'Lcom/google/gdata/client/contacts/ContactsService;' failed
09-10 12:12:44.459: ERROR/dalvikvm(332): Could not find class 'com.google.gdata.client.contacts.ContactsService', referenced from method test34.pkg.Tests34Activity.onCreate
09-10 12:12:44.469: WARN/dalvikvm(332): VFY: unable to resolve new-instance 1142 (Lcom/google/gdata/client/contacts/ContactsService;) in Ltest34/pkg/Tests34Activity;
09-10 12:12:44.469: DEBUG/dalvikvm(332): VFY: replacing opcode 0x22 at 0x0008
09-10 12:12:44.469: DEBUG/dalvikvm(332): VFY: dead code 0x000a-0016 in Ltest34/pkg/Tests34Activity;.onCreate (Landroid/os/Bundle;)V
09-10 12:12:44.609: DEBUG/AndroidRuntime(332): Shutting down VM
09-10 12:12:44.609: WARN/dalvikvm(332): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): FATAL EXCEPTION: main
09-10 12:12:44.639: ERROR/AndroidRuntime(332): java.lang.NoClassDefFoundError: com.google.gdata.client.contacts.ContactsService
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at test34.pkg.Tests34Activity.onCreate(Tests34Activity.java:15)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.os.Looper.loop(Looper.java:123)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 12:12:44.639: ERROR/AndroidRuntime(332): at dalvik.system.NativeStart.main(Native Method)
09-10 12:12:44.659: WARN/ActivityManager(59): Force finishing activity test34.pkg/.Tests34Activity
09-10 12:12:45.159: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{450b53a0 test34.pkg/.Tests34Activity}
09-10 12:12:55.548: WARN/ActivityManager(59): Activity destroy timeout for HistoryRecord{450b53a0 test34.pkg/.Tests34Activity}
I think you getting this type of error
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
Have you added google-collect-1.0-rc1.jar file? if not then I am sure you got the error, this is the dependent file.
you can download from this file from this site and download it and add in your project.

Categories

Resources