layout inflater - Android: Error while adding the xml files to another xml -
error while adding/inflating xml files xml
i trying add xml files xml's while addidng/inflating m getting error.
my main xml is
item_non_highlight.xml
<?xml version="1.0" encoding="utf-8" ?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="10" android:baselinealigned="false"> <linearlayout android:id="@+id/column_big" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="5" android:orientation="vertical" /> <linearlayout android:id="@+id/column_small" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="5" android:orientation="vertical" /> piece of code here shows error
view v = inflater.inflate(r.layout.item_non_highlight, null); linearlayout column_highlight = (linearlayout) v.findviewbyid(r.id.column_big); v = setuphighlightviewtablet(column_highlight); private view setuphighlightviewtablet(view parentview) { int itemcount = 1; linearlayout columnodd = (linearlayout) parentview. findviewbyid(r.id.social_media_column_one); // 2 layouts belongs different xml linearlayout columneven = (linearlayout) parentview. findviewbyid(r.id.social_media_column_two); // view itemview = inflater.inflate(r.layout.highlight, null); if (itemcount % 2 == 0) { columneven.addview(itemview); } else { columnodd.addview(itemview); // error @ ine } } itemcount++; return parentview; } error
java.lang.nullpointerexception: attempt invoke virtual method 'void android.widget.linearlayout.addview(android.view.view)' on null object reference thanks
try inflating layout false flag 3rd param:
view v = inflater.inflate(r.layout.item_non_highlight, null, false); you exception because default android tries add newly inflated view it's parent (second param) , passed there null mentioned exception.
see doc: http://developer.android.com/reference/android/view/layoutinflater.html#inflate(org.xmlpull.v1.xmlpullparser, android.view.viewgroup, boolean)
Comments
Post a Comment