0

メニュー項目のリストを表示する展開可能なリストを作成しようとしています。ただし、実行中にボタンをクリックして新しいアクティビティを実行すると、FATAL EXCEPTION が発生します。

私のソースコードを以下に示します。

public class orders extends ExpandableListActivity{
    //public String NAME="DishName";

    //ExpandableListView explistview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.orders);

        SimpleExpandableListAdapter expListAdapter=
                new SimpleExpandableListAdapter(
                        this,
                        createGroupList(),
                        R.layout.group_row,
                        new String[] { "Group Item" },
                        new int[] { R.id.row_name },
                        createChildList(),
                        R.layout.child_row,
                        new String[] {"Sub Item"},
                        new int[] { R.id.grp_child}
                        );
        setListAdapter(expListAdapter);

    }

    public List createGroupList()
    {
         ArrayList result = new ArrayList();

         HashMap m=new HashMap();
         m.put("Group Item","PIZZA's");
         result.add( m );
    /*   m.put("Group Item","PASTRIES");
         result.add( m );
         m.put("Group Item","CHATS");
         result.add( m );
         m.put("Group Item","MEALS");
         result.add( m );*/
         return (List)result;
    }

    public List createChildList()
    {
        ArrayList result = new ArrayList();
        ArrayList secList = new ArrayList();
        HashMap child = new HashMap();
        child.put( "Sub Item", "Brick oven pizza"); 
        secList.add( child );
        child.put( "Sub Item", "Chicago style"); 
        secList.add( child );
        child.put( "Sub Item", "French break pizza"); 
        secList.add( child );
        child.put( "Sub Item", "Italian pizza"); 
        secList.add( child );
        child.put( "Sub Item", "New York style pizza"); 
        secList.add( child );

        result.add( secList );

        child.put( "Sub Item", "Black Forest"); 
        secList.add( child );
        child.put( "Sub Item", "Chocolate Moose"); 
        secList.add( child );

        result.add( secList );

        child.put( "Sub Item", "Bhel Puri"); 
        secList.add( child );
        child.put( "Sub Item", "Paani Puri"); 
        secList.add( child );
        child.put( "Sub Item", "Masala Puri"); 
        secList.add( child );
        child.put( "Sub Item", "Samosa Masala"); 
        secList.add( child );

        result.add( secList );

        child.put( "Sub Item", "North Indian Meals"); 
        secList.add( child );
        child.put( "Sub Item", "South Indian Meals"); 
        secList.add( child );

        result.add( secList );

        return result;

    }

    public void  onContentChanged  () {
        //System.out.println("onContentChanged");
        Log.d("MYAPP", "onContentChanged....");
        super.onContentChanged();         
    }

     /* This function is called on each child click */
    public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
        //System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
        Log.d("MYAPP","Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
        return true;
    }

    /* This function is called on expansion of the group */
    public void  onGroupExpand  (int groupPosition) {
        try{
             //System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
            Log.d("MYAPP","Group exapanding Listener => groupPosition = " + groupPosition);
        }catch(Exception e){
            //System.out.println(" groupPosition Errrr +++ " + e.getMessage());
            Log.d("MYAPP"," groupPosition Errrr +++ " + e.getMessage());
        }
    }

}

例外の詳細は次のとおりです。

04-09 12:22:02.500: E/AndroidRuntime(22571): FATAL EXCEPTION: main
04-09 12:22:02.500: E/AndroidRuntime(22571): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.takemyorder/com.takemyorder.orders}: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.os.Looper.loop(Looper.java:154)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ActivityThread.main(ActivityThread.java:4624)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at dalvik.system.NativeStart.main(Native Method)
04-09 12:22:02.500: E/AndroidRuntime(22571): Caused by: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ExpandableListActivity.onContentChanged(ExpandableListActivity.java:222)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at com.takemyorder.orders.onContentChanged(orders.java:110)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:257)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.Activity.setContentView(Activity.java:1837)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at com.takemyorder.orders.onCreate(orders.java:26)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.Activity.performCreate(Activity.java:4479)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
04-09 12:22:02.500: E/AndroidRuntime(22571):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
04-09 12:22:02.500: E/AndroidRuntime(22571):    ... 11 more

上記のコードで実行する変更を提案できる人はいますか。前もって感謝します。

4

1 に答える 1

0

展開可能なリストには、 ExpandableListandroid:id="@+id/android:list"でこの属性を設定した ID が必要orders.xmlです。このExpandableListActivity を確認してください

例:

  <ExpandableListView android:id="@id/android:list"
               android:layout_width="match_parent" 
               android:layout_height="match_parent"
               android:background="#00FF00"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>
于 2013-04-09T07:11:29.537 に答える