Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在弹出窗口中切换NullPointerException_Java_Android_Switch Statement - Fatal编程技术网

Java 在弹出窗口中切换NullPointerException

Java 在弹出窗口中切换NullPointerException,java,android,switch-statement,Java,Android,Switch Statement,在settings.xml中: ..... <Switch android:id="@+id/flmode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginLeft="30dp" android:layout_toRightOf

在settings.xml中:

.....
<Switch
    android:id="@+id/flmode"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="30dp"
    android:layout_toRightOf="@+id/textView1" />

<Switch
    android:id="@+id/fmode"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_marginLeft="30dp"
    android:layout_toRightOf="@+id/textView2"/>
.....
启动错误后:

11-15 09:26:08.302: E/AndroidRuntime(11433): FATAL EXCEPTION: main
11-15 09:26:08.302: E/AndroidRuntime(11433): java.lang.NullPointerException
11-15 09:26:08.302: E/AndroidRuntime(11433):    at com.test.com.MainFirst.showPopup(MainFirst.java:507)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at com.test.com.MainFirst.onClick(MainFirst.java:242)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at android.view.View.performClick(View.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at android.view.View$PerformClick.run(View.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at android.os.Handler.handleCallback(Handler.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at android.os.Handler.dispatchMessage(Handler.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at android.os.Looper.loop(Looper.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at android.app.ActivityThread.main(ActivityThread.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at java.lang.reflect.Method.invokeNative(Native Method)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at java.lang.reflect.Method.invoke(Method.java:511)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
11-15 09:26:08.302: E/AndroidRuntime(11433):    at dalvik.system.NativeStart.main(Native Method)
出了什么问题以及如何实施? 提前感谢

您需要做什么

Switch flmode = (Switch) popupView.findViewById(R.id.flmode);
Switch fmode = (Switch) popupView.findViewById(R.id.fmode);
代替

Switch flmode = (Switch) findViewById(R.id.flmode);
Switch fmode = (Switch) findViewById(R.id.fmode);    
Switch flmode = (Switch) findViewById(R.id.flmode);
Switch fmode = (Switch) findViewById(R.id.fmode);