After cleaning RAM app crashes when resuming android app (NullPointerException) - android

I have a problem with my app. I searched for a solution on stackoverflow, but i didn't find one.
I'm still a beginner in developing android apps. I created my first app on my own in the last week.
The problem: When I start the app everything works fine. Also when I start my app, go to menu and resume immediately, but when i switch to menu, clean my memory and then restart my app, it seems, that the app was still running, because it crashes now. I have a similar effect when I start the app, switch to some other apps and then return to my app. In this case, the app also crashes.
So, why the app is still running, altough I cleaned my memory? Should I override onFinish()- or onPause()-method with some basic code I don't know?
And why does the app crash, when i don't use it for a while?
LogCat:
12-18 23:19:06.850: E/AndroidRuntime(25262): FATAL EXCEPTION: main
12-18 23:19:06.850: E/AndroidRuntime(25262): java.lang.NullPointerException
12-18 23:19:06.850: E/AndroidRuntime(25262): at de.dzapps.isoapp.IsoToleranzen.update(IsoToleranzen.java:1293)
12-18 23:19:06.850: E/AndroidRuntime(25262): at de.dzapps.isoapp.IsoToleranzen$4.onItemClick(IsoToleranzen.java:441)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.widget.AbsListView.performItemClick(AbsListView.java:1283)
12-18 23:19:06.850: E/AndroidRuntime(25262): at de.dzapps.isoapp.IsoToleranzen$1.onGlobalLayout(IsoToleranzen.java:174)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:682)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1875)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.os.Handler.handleCallback(Handler.java:615)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.os.Looper.loop(Looper.java:137)
12-18 23:19:06.850: E/AndroidRuntime(25262): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-18 23:19:06.850: E/AndroidRuntime(25262): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 23:19:06.850: E/AndroidRuntime(25262): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 23:19:06.850: E/AndroidRuntime(25262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
12-18 23:19:06.850: E/AndroidRuntime(25262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
12-18 23:19:06.850: E/AndroidRuntime(25262): at dalvik.system.NativeStart.main(Native Method)
Since I get a NullPointerException, it seems, that the system deletes the variables...
But when I doubleclick the third line, eclipse marks this line:
int am_offset = list.getChildAt(0).getTop();
I can't explain this behaviour, because I set a breakpoint at this line and the system never call this expression when I resume the app. list is a ListView.
How can I prevent, that the system deletes the variables, when then app is not used for a while?
Can somebody help me?
Many thanks!

From what I've read, the system deleting variables should be more or less left alone as the system does what it must to keep device performance. It may help to avoid these NullPointerExceptions and restore state by writing safety checks in the onResume of the activity to recreate any lost variables. Also, if they hold data that must persist for long periods of time, SharedPreferences may be of some use for small values and an SQLiteDatabase for when there's a lot to save.

ok I have a solution. I replaced int am_offset = list.getChildAt(0).getTop(); with:
View am_top = list.getChildAt(0);
am_offset = (am_top == null) ? 0 : am_top.getTop();
Now I don't get an exception anymore.
But can somebody explain to me, why the system throws an exception, altough int am_offset = list.getChildAt(0).getTop(); is never called while resuming?
Many thanks!

Related

Use old camera API on lollipop

I have an app that use Camera API that works perfectly on a nexus 7 with kitkat, but after update to lollipop my app crash.
I've decide to use new Camera2 API without success: code works well on a nexus5 but fail on nexus 7.
So i would use old API until i find out where's the problem with new api.
Portion of code that crash is when i initialize camera surface:
#SuppressWarnings("deprecation")
#SuppressLint("InlinedApi")
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
Camera.Parameters params = mCamera.getParameters();
Camera.Size result = getBestPreviewSize(params, width, height);
Log.i("TAG", surfaceView.getWidth() + " " + surfaceView.getHeight());
params.setPreviewSize(result.width, result.height);
params.setPictureFormat(ImageFormat.JPEG);
params.setJpegQuality(100);
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
// params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
// params.setp
params.setPictureSize(dpWidth, dpWidth);
// default orientation is in landscape
params.setRotation(90);
mCamera.setParameters(params);
mCamera.startPreview();
}
crash is on setParameters() instruction:
12-18 10:44:54.130: E/AndroidRuntime(31543): FATAL EXCEPTION: main
12-18 10:44:54.130: E/AndroidRuntime(31543): Process: it.ictinnova.hipstamemostylist, PID: 31543
12-18 10:44:54.130: E/AndroidRuntime(31543): java.lang.RuntimeException: setParameters failed
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.hardware.Camera.native_setParameters(Native Method)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.hardware.Camera.setParameters(Camera.java:1876)
12-18 10:44:54.130: E/AndroidRuntime(31543): at it.ictinnova.hipstamemostylist.ScattaFoto.surfaceChanged(ScattaFoto.java:137)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.SurfaceView.updateWindow(SurfaceView.java:590)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1956)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer.doFrame(Choreographer.java:550)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.os.Handler.handleCallback(Handler.java:739)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.os.Handler.dispatchMessage(Handler.java:95)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.os.Looper.loop(Looper.java:135)
12-18 10:44:54.130: E/AndroidRuntime(31543): at android.app.ActivityThread.main(ActivityThread.java:5221)
12-18 10:44:54.130: E/AndroidRuntime(31543): at java.lang.reflect.Method.invoke(Native Method)
12-18 10:44:54.130: E/AndroidRuntime(31543): at java.lang.reflect.Method.invoke(Method.java:372)
12-18 10:44:54.130: E/AndroidRuntime(31543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-18 10:44:54.130: E/AndroidRuntime(31543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
What's wrong?
this is the same code i used on kitcat
what returns if there is not best preview size in the function of getBestPreviewSize().maybe,code control resolution of the display and the real machine test resolution is different.
try to annotate the code "params.setPreviewSize(result.width, result.height);" and run the code.

my app crashes after adding android:layout_below

i needed help in adding android:layout_below and after adding succesfully now my apps crashes when ever i start to see the result i hope you help me this is my code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/secondLine"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="#string/state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer1"
android:textSize="12sp" />
</RelativeLayout>
and this my logcat
12-18 13:57:18.581: D/AndroidRuntime(2237): Shutting down VM
12-18 13:57:18.581: W/dalvikvm(2237): threadid=1: thread exiting with uncaught exception (group=0x411e62a0)
12-18 13:57:18.581: E/AndroidRuntime(2237): FATAL EXCEPTION: main
12-18 13:57:18.581: E/AndroidRuntime(2237): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1321)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:316)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:337)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5107)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
12-18 13:57:18.581: E/AndroidRuntime(2237): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2361)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.View.measure(View.java:15481)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1999)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1238)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1413)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1131)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4611)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer.doFrame(Choreographer.java:525)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.os.Handler.handleCallback(Handler.java:615)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.os.Looper.loop(Looper.java:137)
12-18 13:57:18.581: E/AndroidRuntime(2237): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-18 13:57:18.581: E/AndroidRuntime(2237): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 13:57:18.581: E/AndroidRuntime(2237): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 13:57:18.581: E/AndroidRuntime(2237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
12-18 13:57:18.581: E/AndroidRuntime(2237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
12-18 13:57:18.581: E/AndroidRuntime(2237): at dalvik.system.NativeStart.main(Native Method)
android:layout_alignBottom="#+id/secondLine" // remove this
for textview1
and
android:layout_below="#id/textView1"
for textView2
causes
java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
Remove one of them and it should work
Place second TextView with id secondLine relative to TextView with id textview1. You have Circular dependencies which is not possible and hence the error.
You need to place once view relative to another.
You are assigning a textView1 to android:layout_alignBottom="#+id/secondLine"
and to second TextView you are assigning secondLine to android:layout_below="#id/textView1"
it mean you are assigning one textview to another and that second to first one.
this is creting Circular dependencies.
You can not assing TextView1 <--> TextView2 connections. you can assign only single side.
remove either of the line.
android:layout_alignBottom="#+id/secondLine"
or
android:layout_below="#id/textView1"
Both TextViews are pointing to each of them like android:layout_alignBottom="#+id/secondLine" and android:layout_below="#id/textView1" so it forms like circular loop, hence you are getting the error. Remove this android:layout_alignBottom="#+id/secondLine" from first textview

Selecting an item in ListFragment list programmatically

I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
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:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}

Run-time error "inflating class fragment"

I have an activity, what I'm trying to do is to start a new activity that holds a Google Maps Fragment API v2 following this example (https://developers.google.com/maps/documentation/android/start). I get an runtime error
"Binary XML file line #4: Error inflating class fragment"
This the XML of activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
and this is the activity's class:
import android.app.Activity;
import android.os.Bundle;
public class MapsActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_act);
// TODO Auto-generated method stub
}
}
and this is the logcat:
12-18 11:59:37.584: W/dalvikvm(9480): threadid=1: thread exiting with uncaught exception (group=0x2b6a3300)
12-18 11:59:37.594: E/AndroidRuntime(9480): FATAL EXCEPTION: main
12-18 11:59:37.594: E/AndroidRuntime(9480): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dimacroitori.supermarket/com.dimacroitori.supermarket.MapsActivity}: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2190)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.access$600(ActivityThread.java:144)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.os.Looper.loop(Looper.java:137)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.main(ActivityThread.java:4939)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.reflect.Method.invoke(Method.java:511)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-18 11:59:37.594: E/AndroidRuntime(9480): at dalvik.system.NativeStart.main(Native Method)
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:257)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Activity.setContentView(Activity.java:1867)
12-18 11:59:37.594: E/AndroidRuntime(9480): at com.exmaple.MapsActivity.onCreate(MapsActivity.java:12)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Activity.performCreate(Activity.java:5008)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-18 11:59:37.594: E/AndroidRuntime(9480): ... 11 more
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Fragment.instantiate(Fragment.java:584)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Fragment.instantiate(Fragment.java:552)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Activity.onCreateView(Activity.java:4656)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
12-18 11:59:37.594: E/AndroidRuntime(9480): ... 20 more
12-18 11:59:37.594: E/AndroidRuntime(9480): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
12-18 11:59:37.594: E/AndroidRuntime(9480): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-18 11:59:37.594: E/AndroidRuntime(9480): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-18 11:59:37.594: E/AndroidRuntime(9480): at android.app.Fragment.instantiate(Fragment.java:574)
12-18 11:59:37.594: E/AndroidRuntime(9480): ... 23 more
Can someone explain me what I'm doing wrong?
Make sure that you have added the Google Play Services Android library project to your application, where that class is defined. Also make sure that you are running your app on an API Level 11 or higher environment, since you are attempting to use native fragments (rather than the Android Support package's backport).

NullPointer exception at android.support.v4.app.FragmentManagerImpl.makeInactive

I'm seeing a weird exception in Android Support Library - the stack trace is below. Any ideas what could be causing this? I'm unable to reproduce the exception on any of my devices, but there seem to be quite a few visible in the Google Play DevConsole.
java.lang.NullPointerException
at android.support.v4.app.FragmentManagerImpl.makeInactive(FragmentManager.java:1133)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
at android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1171)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:582)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
at android.os.Handler.handleCallback(Handler.java:608)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:5045)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
try check stack fragments in time rotate screen for example in onResume.

Categories

Resources