我试图创建一个对话框,它可以工作,除非我尝试添加这个 ListView 部分
protected View onCreateDialogView() {
LayoutInflater inflater = ((SettingsActivity) ctx).getLayoutInflater();
View vw = inflater.inflate(R.layout.channel_content_view, null);
ListView lv = (ListView) vw.findViewById(android.R.id.list);
Log.i("DIALOG", lv.toString()); ---- **RIGHT HERE IT BREAKS at com.example.tvrplayer.ChannelsDialogPreference.onCreateDialogView(ChannelsDialogPreference.java:56)**
return vw;
}
如果我删除该 Listview 位,它会起作用并显示空对话框。
频道内容视图.xml
<LinearLayout
android:id="@+id/channels_list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
</LinearLayout>
堆栈跟踪
02-28 13:37:15.768: E/AndroidRuntime(24732): FATAL EXCEPTION: main
02-28 13:37:15.768: E/AndroidRuntime(24732): java.lang.NullPointerException
02-28 13:37:15.768: E/AndroidRuntime(24732): at com.example.tvrplayer.ChannelsDialogPreference.onCreateDialogView(ChannelsDialogPreference.java:56)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.preference.DialogPreference.showDialog(DialogPreference.java:285)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.preference.DialogPreference.onClick(DialogPreference.java:264)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.preference.Preference.performClick(Preference.java:939)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:202)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.widget.AbsListView.performItemClick(AbsListView.java:1173)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2701)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.widget.AbsListView$1.run(AbsListView.java:3453)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.os.Handler.handleCallback(Handler.java:605)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.os.Handler.dispatchMessage(Handler.java:92)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.os.Looper.loop(Looper.java:137)
02-28 13:37:15.768: E/AndroidRuntime(24732): at android.app.ActivityThread.main(ActivityThread.java:4514)
02-28 13:37:15.768: E/AndroidRuntime(24732): at java.lang.reflect.Method.invokeNative(Native Method)
02-28 13:37:15.768: E/AndroidRuntime(24732): at java.lang.reflect.Method.invoke(Method.java:511)
02-28 13:37:15.768: E/AndroidRuntime(24732): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-28 13:37:15.768: E/AndroidRuntime(24732): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-28 13:37:15.768: E/AndroidRuntime(24732): at dalvik.system.NativeStart.main(Native Method)