錯誤,同時增加/ XML文件中充氣另一個XML安卓:錯誤同時加入了XML文件到另一個XML
我試圖將XML文件添加到另一個XML的,但同時addidng /充氣I M得到的錯誤。
我的主要XML是
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"
/>
一段代碼在這裏表示我的錯誤
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); // this two layouts belongs to a 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 at this ine
}
}
itemCount++;
return parentView;
}
誤差
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.addView(android.view.View)' on a null object reference
感謝
'social_media_column_one'和'social_media_column_two'沒有下'column_big'存在你怎麼能指望這個工作? –
雅我知道,但有沒有可能做到這一點? – Randroid