Android Studio,java.lang.NullPointerException

时间:2020-05-07 22:09:17

标签: java android-studio

嘿,所以我对应用程序进行编码非常陌生,并且在启动该应用程序时遇到了一个我确实不理解的大问题。抱歉,如果这是基本要求,那么我真的很陌生。 错误日志

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
            at android.app.Activity.findViewById(Activity.java:2656)
            at com.example.ledcontrol.MainActivity.<init>(MainActivity.java:35)
            at java.lang.Class.newInstance(Native Method)
            at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
            at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1215)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2831)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
            at android.os.Handler.dispatchMessage(Handler.java:106) 
            at android.os.Looper.loop(Looper.java:193) 
            at android.app.ActivityThread.main(ActivityThread.java:6669) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

 ```

and the code the blue text links to is:

private Button search = findViewById(R.id.search);

Thank you!!

0 个答案:

没有答案