Я получаю NullPointerException
, когда пытаюсь программно добавить раздутые представления к моему ViewFlipper
:
- при создании
setContentView(R.layout.event_report);
final LayoutInflater inflater = getLayoutInflater();
mFlipper = (ViewFlipper) findViewById(R.id.eventReportViewFlipper);
final View typeView = inflater
.inflate(R.layout.event_report_type, null)
mFlipper.addView(typeView, VIEW_TYPE, null); //NullPointerException
- event_report.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/darker_gray"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_dark"
android:gravity="center"
android:text="@string/eventReportCaption"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<ViewFlipper
android:id="@+id/eventReportViewFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
- event_report_type.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/eventReportViewTypeUpperLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/eventReportViewTypeLowerLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Я планирую инициализировать typeView позже.
Вот мой след стека:
11-28 16:59:56.280: E/AndroidRuntime(8604): Caused by: java.lang.NullPointerException
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.view.ViewGroup$LayoutParams.<init>(ViewGroup.java:3582)
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3732)
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:492)
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:436)
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.view.ViewGroup.addViewInner(ViewGroup.java:1984)
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.view.ViewGroup.addView(ViewGroup.java:1874)
11-28 16:59:56.280: E/AndroidRuntime(8604): at android.widget.ViewAnimator.addView(ViewAnimator.java:160)
11-28 16:59:56.280: E/AndroidRuntime(8604): at fi.emicode.flashpoint.EventDialog.onCreate(EventDialog.java:43)