Application Crashes when an Activity that Extends ListView is 'Launched'

1.3k views Asked by At

Here is my InfoBookActivity.java

package thesleeplesselite.drgreenthumb;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class InfoBookActivity extends ListActivity {

    // -- AUTO-GENERATED CODE --

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_infobook);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_infobook, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        // noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    // -- END OF AUTO-GENERATED CODE --
}

I want to set it using a custom layout and this is the code for my xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="thesleeplesselite.drgreenthumb.InfoBookActivity"
    android:background="#6E5E63"
    android:id="@+id/linearLayoutVertical"
    android:focusableInTouchMode="false">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayoutHorizontal"
        android:gravity="center_vertical"
        android:weightSum="1"
        android:layout_marginBottom="5dp">

        <ImageView
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:id="@+id/imgIconSearch"
            android:src="@drawable/icon_search"
            android:contentDescription="@string/str_imgIconSearch"
            android:layout_marginRight="10dp"
            android:layout_weight="0.01"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/txtEIBSearchBar"
            android:layout_weight="0.99"
            android:inputType="text"
            android:hint="@string/str_txtEIBSearchBar"
            android:textColorHint="#E8CDBC"
            android:textColor="#E8CDBC" />
    </LinearLayout>

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/list"
        android:background="#EDE5DA" />

</LinearLayout>

And here's my logcat:

06-16 03:35:29.180    2593-2601/? E/art﹕ Thread attaching while runtime is shutting down: Binder_1
06-16 03:35:29.180    2593-2601/? I/AndroidRuntime﹕ NOTE: attach of thread 'Binder_1' failed
06-16 03:35:29.195      945-945/? I/art﹕ Background concurrent mark sweep GC freed 785(33KB) AllocSpace objects, 0(0B) LOS objects, 91% free, 93KB/1117KB, paused 5.193ms total 20.045ms
06-16 03:35:29.207    1242-2223/? I/ActivityManager﹕ Start proc 2602:thesleeplesselite.drgreenthumb/u0a58 for activity thesleeplesselite.drgreenthumb/.MainActivity
06-16 03:35:29.221    2602-2602/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
06-16 03:35:29.736    2602-2614/? I/art﹕ Background sticky concurrent mark sweep GC freed 2740(227KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 7MB/7MB, paused 92.395ms total 130.649ms
06-16 03:35:29.848    2602-2617/? D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-16 03:35:29.852    2602-2602/? D/﹕ HostConnection::get() New Host Connection established 0xb42b3e60, tid 2602
06-16 03:35:29.940    2602-2602/? D/Atlas﹕ Validating map...
06-16 03:35:29.942    1242-1591/? V/WindowManager﹕ Adding window Window{3d9b73de u0 thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity} at 2 of 8 (before Window{c47461d u0 Starting thesleeplesselite.drgreenthumb})
06-16 03:35:30.076    2602-2617/? D/﹕ HostConnection::get() New Host Connection established 0xb43f5090, tid 2617
06-16 03:35:30.193    2602-2617/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-16 03:35:30.240    2602-2617/? D/OpenGLRenderer﹕ Enabling debug mode 0
06-16 03:35:30.280    2602-2617/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
06-16 03:35:30.280    2602-2617/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb43891e0, error=EGL_SUCCESS
06-16 03:35:30.929    1242-1265/? I/Choreographer﹕ Skipped 97 frames!  The application may be doing too much work on its main thread.
06-16 03:35:31.885    2602-2602/? I/Choreographer﹕ Skipped 90 frames!  The application may be doing too much work on its main thread.
06-16 03:35:31.904    1242-1265/? I/ActivityManager﹕ Displayed thesleeplesselite.drgreenthumb/.MainActivity: +2s731ms (total +6m57s110ms)
06-16 03:35:32.759    1242-1300/? D/TaskPersister﹕ removeObsoleteFile: deleting file=66_task.xml
06-16 03:39:59.597    1242-1334/? D/ConnectivityService﹕ reportBadNetwork(NetworkAgentInfo [MOBILE (UMTS) - 100]) by 10007
06-16 03:39:59.597    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ ValidatedState{ when=-1ms what=532488 arg1=10007 target=com.android.internal.util.StateMachine$SmHandler }
06-16 03:39:59.597    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ DefaultState{ when=-1ms what=532488 arg1=10007 target=com.android.internal.util.StateMachine$SmHandler }
06-16 03:39:59.597    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Forcing reevaluation
06-16 03:39:59.598    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ EvaluatingState{ when=0 what=532486 arg1=15 target=com.android.internal.util.StateMachine$SmHandler }
06-16 03:39:59.598    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Checking http://connectivitycheck.android.com/generate_204 on epc.tmobile.com
06-16 03:39:59.689    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ isCaptivePortal: ret=204 headers={null=[HTTP/1.1 204 No Content], Content-Length=[0], Date=[Mon, 15 Jun 2015 19:46:35 GMT], Server=[GFE/2.0], X-Android-Received-Millis=[1434397199689], X-Android-Response-Source=[NETWORK 204], X-Android-Sent-Millis=[1434397199656]}
06-16 03:39:59.689    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Don't send network conditions - lacking user consent.
06-16 03:39:59.689    1242-1626/? D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]﹕ Validated
06-16 03:39:59.690    1242-1286/? D/ConnectivityService﹕ setProvNotificationVisibleIntent: E visible=false networkType=0 extraInfo=null
06-16 03:39:59.690    1242-1286/? D/ConnectivityService﹕ Validated NetworkAgentInfo [MOBILE (UMTS) - 100]
06-16 03:40:04.999    1667-2623/? D/GCM﹕ Connected
06-16 03:40:05.047    1667-2623/? D/GCM﹕ Message class com.google.e.a.a.q
06-16 03:41:25.432    1242-2221/? I/ActivityManager﹕ START u0 {cmp=thesleeplesselite.drgreenthumb/.InfoBookActivity} from uid 10058 on display 0
06-16 03:41:25.434    1242-2221/? V/WindowManager﹕ addAppToken: AppWindowToken{1f619242 token=Token{3ceaf08d ActivityRecord{1bdefd24 u0 thesleeplesselite.drgreenthumb/.InfoBookActivity t67}}} to stack=1 task=67 at 1
06-16 03:41:25.440    1242-1290/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
06-16 03:41:25.599    2602-2602/? D/AndroidRuntime﹕ Shutting down VM
    --------- beginning of crash
06-16 03:41:25.600    2602-2602/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: thesleeplesselite.drgreenthumb, PID: 2602
    java.lang.RuntimeException: Unable to start activity ComponentInfo{thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.InfoBookActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
            at android.app.ListActivity.onContentChanged(ListActivity.java:243)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:382)
            at android.app.Activity.setContentView(Activity.java:2145)
            at thesleeplesselite.drgreenthumb.InfoBookActivity.onCreate(InfoBookActivity.java:16)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
06-16 03:41:25.657    1242-2222/? W/ActivityManager﹕ Force finishing activity 1 thesleeplesselite.drgreenthumb/.InfoBookActivity
06-16 03:41:25.672    1242-2222/? W/ActivityManager﹕ Force finishing activity 2 thesleeplesselite.drgreenthumb/.MainActivity
06-16 03:41:25.830    1242-2499/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-16 03:41:25.936    1242-2499/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
06-16 03:41:25.936    1242-2499/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2046500, error=EGL_SUCCESS
06-16 03:41:26.320    1242-1260/? W/ActivityManager﹕ Activity pause timeout for ActivityRecord{1bdefd24 u0 thesleeplesselite.drgreenthumb/.InfoBookActivity t67 f}
06-16 03:41:26.405    1463-1612/? I/OpenGLRenderer﹕ Initialized EGL, version 1.4
06-16 03:41:26.482    1463-1612/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
06-16 03:41:26.482    1463-1612/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5a04380, error=EGL_SUCCESS
06-16 03:41:26.751    1463-1478/? I/art﹕ Background sticky concurrent mark sweep GC freed 2635(114KB) AllocSpace objects, 2(33KB) LOS objects, 0% free, 20MB/20MB, paused 13.027ms total 45.840ms
06-16 03:41:27.046    1463-1478/? I/art﹕ Background partial concurrent mark sweep GC freed 7650(606KB) AllocSpace objects, 30(7MB) LOS objects, 22% free, 13MB/17MB, paused 2.534ms total 146.769ms
06-16 03:41:27.357    1317-1317/? W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000
06-16 03:41:27.357    1317-1317/? W/PackageManager﹕ Failure retrieving resources for thesleeplesselite.drgreenthumb: Resource ID #0x0
06-16 03:41:27.472    1463-1478/? I/art﹕ Background sticky concurrent mark sweep GC freed 285(36KB) AllocSpace objects, 6(124KB) LOS objects, 3% free, 17MB/17MB, paused 22.838ms total 66.592ms
06-16 03:41:29.182    1242-1290/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
06-16 03:41:29.205    2602-2602/? I/Process﹕ Sending signal. PID: 2602 SIG: 9
06-16 03:41:29.240    1242-1275/? W/InputDispatcher﹕ channel '3d9b73de thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
06-16 03:41:29.240    1242-1275/? E/InputDispatcher﹕ channel '3d9b73de thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
06-16 03:41:29.241    1242-2499/? D/OpenGLRenderer﹕ endAllStagingAnimators on 0x9e152d00 (RippleDrawable) with handle 0xa2363ab0
06-16 03:41:29.247    1242-2220/? E/JavaBinder﹕ !!! FAILED BINDER TRANSACTION !!!
06-16 03:41:29.248    1242-2220/? W/InputMethodManagerService﹕ Got RemoteException sending setActive(false) notification to pid 2602 uid 10058
06-16 03:41:29.248    1242-2220/? E/JavaBinder﹕ !!! FAILED BINDER TRANSACTION !!!
06-16 03:41:29.280    1242-1585/? I/ActivityManager﹕ Process thesleeplesselite.drgreenthumb (pid 2602) has died
06-16 03:41:29.281    1242-2223/? I/WindowState﹕ WIN DEATH: Window{3d9b73de u0 thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity}
06-16 03:41:29.281    1242-2223/? W/InputDispatcher﹕ Attempted to unregister already unregistered input channel '3d9b73de thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity (server)'
06-16 03:41:29.798    1463-1612/? W/OpenGLRenderer﹕ Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...

I don't understand? I think I've already named my ListView 'list', as stated in my xml file.

I'm new to this Android thing, so maybe a noob-friendly explanation would help. Thank you.

1

There are 1 answers

2
Eric Levine On BEST ANSWER

The key is this from your stack trace:

Your content must have a ListView whose id attribute is 'android.R.id.list'

Your ListView in the xml layout needs the following id:

<ListView
  android:id="@android:id/list"

(notice its not @+/id)