Search code examples
androidslidingdrawer

The handle attribute is must refer to an existing child while implementing SlidingDrawer


I am trying to implement SlidingDrawer. My app is crashing.

XML FILE

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SlidingDrawer
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:content="@+id/content"
        android:handle="@+id/handle" >
    </SlidingDrawer>

    <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#C0C0C0"
        android:gravity="center|top"
        android:orientation="vertical"
        android:padding="10dip" >

        <include
            android:id="@+id/include1"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            layout="@layout/header_history" >
        </include>

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:cacheColorHint="#00000000"
            android:divider="@android:color/black"
            android:dividerHeight="1.0sp"
            android:textColor="#000000" />
    </LinearLayout>

</LinearLayout>

LogCat

12-25 17:40:33.582: E/AndroidRuntime(454): FATAL EXCEPTION: main
12-25 17:40:33.582: E/AndroidRuntime(454): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demohistory/com.example.demohistory.History}: java.lang.IllegalArgumentException: The handle attribute is must refer to an existing child.
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.os.Looper.loop(Looper.java:123)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-25 17:40:33.582: E/AndroidRuntime(454):  at java.lang.reflect.Method.invokeNative(Native Method)
12-25 17:40:33.582: E/AndroidRuntime(454):  at java.lang.reflect.Method.invoke(Method.java:521)
12-25 17:40:33.582: E/AndroidRuntime(454):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-25 17:40:33.582: E/AndroidRuntime(454):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-25 17:40:33.582: E/AndroidRuntime(454):  at dalvik.system.NativeStart.main(Native Method)
12-25 17:40:33.582: E/AndroidRuntime(454): Caused by: java.lang.IllegalArgumentException: The handle attribute is must refer to an existing child.
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.widget.SlidingDrawer.onFinishInflate(SlidingDrawer.java:239)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-25 17:40:33.582: E/AndroidRuntime(454):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.Activity.setContentView(Activity.java:1647)
12-25 17:40:33.582: E/AndroidRuntime(454):  at com.example.demohistory.History.onCreate(History.java:59)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-25 17:40:33.582: E/AndroidRuntime(454):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-25 17:40:33.582: E/AndroidRuntime(454):  ... 11 more

Solution

  • Caused by: java.lang.IllegalArgumentException: The handle attribute is must refer to an existing child.
    

    This error is occurred as you have specified

    android:handle="@+id/handle" 
    

    in SlidingDrawer's properties. But you have there is no any existing child of Sliding drawer with id 'handle'.

    Check documentation for handle property:

    Identifier for the child that represents the drawer's handle.

    Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

    So you will have to modify your xml file as something like:

    <SlidingDrawer
            android:id="@+id/drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:content="@+id/content"
            android:handle="@+id/handle" >
    
        <ImageView
                 android:id="@id/handle"
                 android:layout_width="88dip"
                 android:layout_height="44dip" />
    
    </SlidingDrawer>
    

    Hope it helps.