view - NullPointerException when using .addView to ViewGroup -
i'm trying use .addview
add linearlayout
viewgroup
.
i getting following error on logcat:
05-21 16:23:04.096: e/androidruntime(2086): fatal exception: main 05-21 16:23:04.096: e/androidruntime(2086): java.lang.nullpointerexception 05-21 16:23:04.096: e/androidruntime(2086): @ android.view.viewgroup.addview(viewgroup.java:3148) 05-21 16:23:04.096: e/androidruntime(2086): @ android.view.viewgroup.addview(viewgroup.java:3131)
this code being called:
final linearlayout eventcontainersub = (linearlayout) findviewbyid(r.layout.event_container); final linearlayout eventcontainer = (linearlayout) findviewbyid(r.id.eventcontainer); eventcontainer.addview(eventcontainersub);
here viewgroup
(the first linear layout):
<linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:animatelayoutchanges="true" android:id="@+id/eventcontainer" android:weightsum="100" android:duplicateparentstate="true">
and (second) linearlayout
i'm adding (first one) linearlayout
above:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/eventcontainersub">
both containers have exact same name..eventcontainersub.
there no eventcontainer, change view group container planned..
<linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:animatelayoutchanges="true" android:id="@+id/event_container" android:weightsum="100" android:duplicateparentstate="true">
and make sure code asking right ids:
final linearlayout eventcontainersub = (linearlayout) findviewbyid(r.layout.eventcontainersub);
final linearlayout eventcontainer = (linearlayout) findviewbyid(r.id.event_container);
i'd suggest first remove subcontainer view if got inflated, view has parent , cannot attach subcontainer 2 parents.
either leave subcontainer file , create new one, or remove parent , add viewgroup want.
Comments
Post a Comment