Android Runtime Exception while creating expandable list -
i'm trying create expandable list shows list of menu items. while execution, on button click new activity leads fatal exception.
my source code shown below:
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(); } /* function called on each child click */ public boolean onchildclick( expandablelistview parent, view v, int groupposition,int childposition,long id) { //system.out.println("inside onchildclick @ groupposition = " + groupposition +" child clicked @ position " + childposition); log.d("myapp","inside onchildclick @ groupposition = " + groupposition +" child clicked @ position " + childposition); return true; } /* function called on expansion of 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()); } } }
below details of exception:
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 start activity componentinfo{com.takemyorder/com.takemyorder.orders}: java.lang.runtimeexception: content must have expandablelistview id attribute 'android.r.id.list' 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activitythread.performlaunchactivity(activitythread.java:2077) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2104) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activitythread.access$600(activitythread.java:134) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activitythread$h.handlemessage(activitythread.java:1247) 04-09 12:22:02.500: e/androidruntime(22571): @ android.os.handler.dispatchmessage(handler.java:99) 04-09 12:22:02.500: e/androidruntime(22571): @ android.os.looper.loop(looper.java:154) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activitythread.main(activitythread.java:4624) 04-09 12:22:02.500: e/androidruntime(22571): @ java.lang.reflect.method.invokenative(native method) 04-09 12:22:02.500: e/androidruntime(22571): @ java.lang.reflect.method.invoke(method.java:511) 04-09 12:22:02.500: e/androidruntime(22571): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:809) 04-09 12:22:02.500: e/androidruntime(22571): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:576) 04-09 12:22:02.500: e/androidruntime(22571): @ dalvik.system.nativestart.main(native method) 04-09 12:22:02.500: e/androidruntime(22571): caused by: java.lang.runtimeexception: content must have expandablelistview id attribute 'android.r.id.list' 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.expandablelistactivity.oncontentchanged(expandablelistactivity.java:222) 04-09 12:22:02.500: e/androidruntime(22571): @ com.takemyorder.orders.oncontentchanged(orders.java:110) 04-09 12:22:02.500: e/androidruntime(22571): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:257) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activity.setcontentview(activity.java:1837) 04-09 12:22:02.500: e/androidruntime(22571): @ com.takemyorder.orders.oncreate(orders.java:26) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activity.performcreate(activity.java:4479) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1050) 04-09 12:22:02.500: e/androidruntime(22571): @ android.app.activitythread.performlaunchactivity(activitythread.java:2041) 04-09 12:22:02.500: e/androidruntime(22571): ... 11 more
can suggest changes performed in above code. in advance.
your expandable list must have id android:id="@+id/android:list"
set attribute in orders.xml
expandablelist . check expandablelistactivity
example:
<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"/>
Comments
Post a Comment