I’ve got a ExpandableListView which when I click to expand the child it throws a “Id not found” error when I try and update the Text on a TextView in the child Layout. If I comment this section out it works fine. I’ve based my project off examples I’ve found round the place. Can anyone spot where I’ve gone wrong?
Here’s the child layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView android:id="@+id/breakdown_item_a"
android:layout_height="40dip"
android:layout_width="40dip"
android:layout_marginLeft="40dip"
android:text="A" />
<TextView android:id="@+id/breakdown_item_b"
android:layout_height="40dip"
android:layout_width="40dip"
android:layout_marginLeft="40dip"
android:text="B" />
</LinearLayout>
And then here is the code that creates the child view:
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View rowView, ViewGroup parent) {
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.list_level_breakdown_item, null);
}
// If I comment out the next few lines it works, else it crashes here
((TextView)rowView.findViewById(R.id.breakdown_item_a)).setText(this.getChild(groupPosition, childPosition).getA()); ((TextView)rowView.findViewById(R.id.breakdown_item_b)).setText(this.getChild(groupPosition, childPosition).getB());
return rowView;
}
Finally got to my PC and this is the error message that is being thrown. Looking at the stack trace it seems to be something wrong with the view not the retrieval of the Id itself:
FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: String resource ID #0xa
at android.content.res.Resources.getText(Resources.java:247)
at android.widget.TextView.setText(TextView.java:3473)
at testing.android.arrayadapters.BreakdownArray.getChildView(BreakdownArray.java:50)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:450)
at android.widget.AbsListView.obtainView(AbsListView.java:2033)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
at android.widget.ListView.onMeasure(ListView.java:1155)
at android.view.View.measure(View.java:12723)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:12723)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12723)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12723)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1196)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
at android.view.View.measure(View.java:12723)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12723)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
at android.view.View.measure(View.java:12723)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
at android.view.View.measure(View.java:12723)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Seems that it doesn’t like the measurement of something. I’ve updated the code (layout and child view). I’ve tried updating things to a fixed width to see if that helps. No luck so far will continue tinkering
Ok I’ve found out the reason. It would seem that the getA() method since it returned an int this caused it to crash as it doesn’t auto convert it to a String. So that was nice pain in the ass for no reason at all 🙁 sorry bout the confusion guys. But the overall lesson is:
If you’re going to assign the text value of a textview ALWAYS explictly convert to a string when passing in the parameter as it wont throw errors…but will crash when you run it.
Cheers for looking at it though.