yesterday one of our customers reported that our app crashes on his Xperia Z1 with Android 4.4.2. After testing in an avd, we found out, that this exception doesn't happen on API 18 or earlier. The app crashes after the Dialog is returned but the reason seems to be the AlertDialog.setView because if we remove this line, the app doesn't crash.
I already spent quite some time searching the web for a solution and trying different approaches but didn't find anything that's helping me.
Are there any known problems with API 19 and AlertDialog.setView? Are we doing something wrong? Does someone have an idea how to solve this?
Thanks in advance
Dirk
This is the (simplified, but still crashing) code i'm creating the dialog with:
AlertDialog alert = null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false).setPositiveButton("OK",
new DialogInterface.OnClickListener()
{
...
});
builder.setNeutralButton(
getResources().getString(R.string.text_button_help),
new DialogInterface.OnClickListener()
{
...
});
builder.setView(this.getLayoutInflater().inflate(R.layout.timeline,
null));
alert = builder.create();
return alert;
And the LogCat output:
06-11 06:44:25.710: E/ViewRootImpl(1188): Attempting to destroy the window while drawing!
06-11 06:44:25.710: E/ViewRootImpl(1188): window=android.view.ViewRootImpl#b237f958, title=foo/bar
06-11 06:44:25.820: W/dalvikvm(1188): threadid=1: thread exiting with uncaught exception (group=0xb1a3aba8)
06-11 06:44:25.840: E/AndroidRuntime(1188): FATAL EXCEPTION: main
06-11 06:44:25.840: E/AndroidRuntime(1188): Process: foo, PID: 1188
06-11 06:44:25.840: E/AndroidRuntime(1188): java.lang.IllegalStateException: Surface has already been released.
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Surface.checkNotReleasedLocked(Surface.java:408)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Surface.unlockCanvasAndPost(Surface.java:261)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2507)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2409)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2253)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1883)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer.doFrame(Choreographer.java:544)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.os.Handler.handleCallback(Handler.java:733)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.os.Handler.dispatchMessage(Handler.java:95)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.os.Looper.loop(Looper.java:136)
06-11 06:44:25.840: E/AndroidRuntime(1188): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-11 06:44:25.840: E/AndroidRuntime(1188): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 06:44:25.840: E/AndroidRuntime(1188): at java.lang.reflect.Method.invoke(Method.java:515)
06-11 06:44:25.840: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-11 06:44:25.840: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-11 06:44:25.840: E/AndroidRuntime(1188): at dalvik.system.NativeStart.main(Native Method)
we finally figured it out by ourselves, at least how we get it to work. the problem has been that we were still using the deprecated showDialog()-method instead of DialogFragments. It seems there are cases in which showDialog() and AlertDialog.setView() don't work together, in other cases they obviously do, we had another dialog which was still working. After introducing DialogFragments to our app the dialog starts just like in previous API-versions.
Related
This question already has answers here:
Your content must have a ListView whose id attribute is 'android.R.id.list'
(7 answers)
Closed 7 years ago.
LogCat
06-02 15:53:34.742: E/Trace(1188): error opening trace file: No such file or directory (2)
06-02 15:53:36.682: D/dalvikvm(1188): GC_FOR_ALLOC freed 49K, 7% free 2539K/2708K, paused 483ms, total 484ms
06-02 15:53:36.712: I/dalvikvm-heap(1188): Grow heap (frag case) to 3.666MB for 1127536-byte allocation
06-02 15:53:36.782: D/dalvikvm(1188): GC_FOR_ALLOC freed 1K, 5% free 3639K/3812K, paused 69ms, total 69ms
06-02 15:53:36.902: D/dalvikvm(1188): GC_CONCURRENT freed <1K, 5% free 3639K/3812K, paused 15ms+42ms, total 123ms
06-02 15:53:37.672: I/Choreographer(1188): Skipped 49 frames! The application may be doing too much work on its main thread.
06-02 15:53:37.705: D/gralloc_goldfish(1188): Emulator without GPU emulation detected.
06-02 15:53:40.412: D/AndroidRuntime(1188): Shutting down VM
06-02 15:53:40.412: W/dalvikvm(1188): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-02 15:53:40.612: E/AndroidRuntime(1188): FATAL EXCEPTION: main
06-02 15:53:40.612: E/AndroidRuntime(1188): java.lang.RuntimeException: Unable to start activity ComponentInfo{testing.android.application.three/testing.android.application.three.MainActivityNext}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.os.Looper.loop(Looper.java:137)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-02 15:53:40.612: E/AndroidRuntime(1188): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 15:53:40.612: E/AndroidRuntime(1188): at java.lang.reflect.Method.invoke(Method.java:511)
06-02 15:53:40.612: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-02 15:53:40.612: E/AndroidRuntime(1188): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-02 15:53:40.612: E/AndroidRuntime(1188): at dalvik.system.NativeStart.main(Native Method)
06-02 15:53:40.612: E/AndroidRuntime(1188): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
06-02 15:53:40.612: E/AndroidRuntime(1188): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.Activity.setContentView(Activity.java:1881)
06-02 15:53:40.612: E/AndroidRuntime(1188): at testing.android.application.three.MainActivityNext.onCreate(MainActivityNext.java:28)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.Activity.performCreate(Activity.java:5104)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-02 15:53:40.612: E/AndroidRuntime(1188): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-02 15:53:40.612: E/AndroidRuntime(1188): ... 11 more
06-02 15:53:44.662: I/Process(1188): Sending signal. PID: 1188 SIG: 9
Your problem is you are trying to extends ListActivity and you don't have a ListView with
android:id="android.R.id.list"
You need to have a ListView in your xml with that id. Please add it to your xml
You can tell by the following line in your logcat
Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
If you find the next line that references your Activity it will tell you the class and line number
at testing.android.application.three.MainActivityNext.onCreate(MainActivityNext.java:28)
So MainActivityNext line 28 is showing the exception.
Note
As stated in a comment, please don't just post unformatted logcat when asking for help. Please try to look for where the error is occurring and post relevant code along with a description of what the problem is. This one was easy to see from the error but usually we will need to see some code
You can use CTRL+K to format your code and logcat or use the coding brackets above {}
You have defined a ListViewActivity (I guess), but it doesn't have a #android:id/list. You should change the ID of your ListView like this:
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
I'm currently using this code to assign a color and opacity for a widget-textview:
remoteViews.setTextColor(R.id.nextAlarm_textview, Color.parseColor(text_opacity + text_color));
Now I would like to do the same with the widget's background. Is that possible?
I tried something like this, but it's not working(invalid int):
remoteViews.setInt(R.id.widget_relative, "setBackgroundColor", Integer.parseInt(background_opacity + background_color));
background_opacity is #FF, background_color is 000000 for example. Both are strings.
/edit:
> 08-24 19:28:48.964 15059-15059/com.widget E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.widget, PID: 15059
java.lang.NumberFormatException: Invalid int: "#FFFFFFFF"
at java.lang.Integer.invalidInt(Integer.java:137)
at java.lang.Integer.parse(Integer.java:374)
at java.lang.Integer.parseInt(Integer.java:365)
at java.lang.Integer.parseInt(Integer.java:331)
at com.widget.WidgetSettings$10.onClick(WidgetSettings.java:256)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
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));
}
I am making my first android app. I want to disable a tab bat item in my android app. I searched and found the following way to do that:
tabHost = (TabHost)findViewById(R.id.tabhost);
tabHost.getTabWidget().getChildTabViewAt(your_index).setEnabled(false);
but its not working and i am getting following error:
06-11 16:53:15.927: D/AndroidRuntime(8466): Shutting down VM
06-11 16:53:15.927: W/dalvikvm(8466): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
06-11 16:53:16.037: D/dalvikvm(8466): GC_FOR_MALLOC freed 5350 objects / 347632 bytes in 98ms
06-11 16:53:16.047: E/AndroidRuntime(8466): FATAL EXCEPTION: main
06-11 16:53:16.047: E/AndroidRuntime(8466): java.lang.IllegalStateException: Could not execute method of the activity
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View$1.onClick(View.java:2072)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View.performClick(View.java:2408)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View$PerformClick.run(View.java:8817)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.os.Handler.handleCallback(Handler.java:587)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.os.Handler.dispatchMessage(Handler.java:92)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.os.Looper.loop(Looper.java:143)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.app.ActivityThread.main(ActivityThread.java:4914)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invoke(Method.java:521)
06-11 16:53:16.047: E/AndroidRuntime(8466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-11 16:53:16.047: E/AndroidRuntime(8466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-11 16:53:16.047: E/AndroidRuntime(8466): at dalvik.system.NativeStart.main(Native Method)
06-11 16:53:16.047: E/AndroidRuntime(8466): Caused by: java.lang.reflect.InvocationTargetException
06-11 16:53:16.047: E/AndroidRuntime(8466): at com.eplinovo.runnoandroid.ActivityViewActivity.startClick(ActivityViewActivity.java:40)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invoke(Method.java:521)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View$1.onClick(View.java:2067)
06-11 16:53:16.047: E/AndroidRuntime(8466): ... 11 more
06-11 16:53:16.047: E/AndroidRuntime(8466): Caused by: java.lang.NullPointerException
06-11 16:53:16.047: E/AndroidRuntime(8466): ... 15 more
Why am i getting that? Thanks in advance.
Ok. Go to the top of the error in logcat, which is ActivityViewActivity.startClick. Go ahead and click on this line. It will take you to some line in startClick method where there is a null pointer exeption. Tell us what is on that line. It might be the line above. If it is than for example
tabHost might be null. Check this separately.
tabHost.getWidget()
tagHost.getWidget().getChildTabViewAt(your_index) // I bet its this one thats null.
if any of the above are null you will get that exception assumming that the line causing the problem. If not its something similar on another line.
So divide and conquer. Find the line. Split it up to find what might be null. Then set a breakpoint before the line runs, and step one line at a time. Hover over to see what is null at each step. Thats how you can solve any null pointer in android.
I was not getting tabhost in right way.
tabHost = (TabHost)findViewById(R.id.tabhost);
Following is the right way to get tabhost from child activity:
tabHost = (TabHost)getParent().findViewById(android.R.id.tabhost);
In my app I want to open a MapActivity from a button click. But on the button click,its showing a class not found error.
Im posting my error log also,so that it will be easy to correct me...
06-11 17:16:53.854: WARN/dalvikvm(890): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): FATAL EXCEPTION: main
06-11 17:16:53.865: ERROR/AndroidRuntime(890): java.lang.NoClassDefFoundError: com.iqmobi.SampleMapPage
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at com.iqmobi.Login.onClick(Login.java:61)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at android.view.View.performClick(View.java:2408)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at android.view.View$PerformClick.run(View.java:8816)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at android.os.Handler.handleCallback(Handler.java:587)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at android.os.Handler.dispatchMessage(Handler.java:92)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at android.os.Looper.loop(Looper.java:123)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at java.lang.reflect.Method.invoke(Method.java:521)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-11 17:16:53.865: ERROR/AndroidRuntime(890): at dalvik.system.NativeStart.main(Native Method)
06-11 17:16:53.874: WARN/ActivityManager(60): Force finishing activity com.iqmobi/.Login
06-11 17:16:54.384: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{4505c5d8 com.iqmobi/.Login}
The code which is moving to the MapActivity is
Intent successIntent=new Intent(Login.this,SampleMapPage.class);
startActivity(successIntent);
An additional information i checked,that,when i Toast instead of startActivity in my above code section,its working....Its something related to the button click,i think.....please help
Add <uses-library android:name="com.google.android.maps" /> to your manifest and make sure you're using the Google API version of Android. Your manifest should look something like the one in this question.
Write Below Code line into your manifest file's <application> tag.
<uses-library android:name="com.google.android.maps" />