java.lang.NullPointerException:尝试调用虚方法'android.view.Window $ Callback android.view.Window.getCallback()'

时间:2017-10-31 20:17:01

标签: android nullpointerexception runtime-error

当我想在手机上运行ProjectPlannerPro应用程序时,我遇到了问题。我在Windows 7 - 64位中使用Android Studio 3.0。

问题在于,当我尝试在手机中运行应用程序(三星Galaxy S6 Edge Plus,Android版本7.0,API 24)时,它会崩溃。

这是运行后的logcat:

10-31 22:52:30.773 22504-22504/? E/Zygote: v2
10-31 22:52:30.773 22504-22504/? I/libpersona: KNOX_SDCARD checking this for 10406
10-31 22:52:30.773 22504-22504/? I/libpersona: KNOX_SDCARD not a persona
10-31 22:52:30.774 22504-22504/? E/Zygote: accessInfo : 0
10-31 22:52:30.774 22504-22504/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2],  Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0009, [-1 -1 -4 -1 0 1]
10-31 22:52:30.775 22504-22504/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.planner.reemshams.projectplannerpro 
10-31 22:52:30.777 22504-22504/? I/art: Late-enabling -Xcheck:jni
10-31 22:52:30.792 22504-22504/? D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
10-31 22:52:30.827 22504-22504/? W/System: ClassLoader referenced unknown path: /data/app/com.planner.reemshams.projectplannerpro-2/lib/arm64
10-31 22:52:30.858 22504-22504/com.planner.reemshams.projectplannerpro D/AndroidRuntime: Shutting down VM
10-31 22:52:30.859 22504-22504/com.planner.reemshams.projectplannerpro E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                         Process: com.planner.reemshams.projectplannerpro, PID: 22504
                                                                                         java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.planner.reemshams.projectplannerpro/com.planner.reemshams.projectplannerpro.Register}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819)
                                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
                                                                                             at android.app.ActivityThread.-wrap14(ActivityThread.java)
                                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
                                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                             at android.os.Looper.loop(Looper.java:154)
                                                                                             at android.app.ActivityThread.main(ActivityThread.java:6682)
                                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
                                                                                          Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
                                                                                             at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:117)
                                                                                             at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:149)
                                                                                             at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
                                                                                             at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:54)
                                                                                             at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:31)
                                                                                             at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:31)
                                                                                             at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
                                                                                             at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
                                                                                             at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
                                                                                             at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
                                                                                             at com.planner.reemshams.projectplannerpro.Register.<init>(Register.java:12)
                                                                                             at java.lang.Class.newInstance(Native Method)
                                                                                             at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
                                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
                                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
                                                                                             at android.app.ActivityThread.-wrap14(ActivityThread.java) 
                                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
                                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                             at android.os.Looper.loop(Looper.java:154) 
                                                                                             at android.app.ActivityThread.main(ActivityThread.java:6682) 
                                                                                             at java.lang.reflect.Method.invoke(Native Method) 
                                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
                                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

这是我的AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.planner.reemshams.projectplannerpro">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Projects List"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name=".Register"
            android:label="Register">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".LoginActivity"
            android:label="Login">
            <intent-filter>
                <action android:name="com.planner.reemshams.projectplannerpro.LoginActivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name=".ProjectsList"
            android:label="Projects List">
            <intent-filter>
                <action android:name="com.planner.reemshams.projectplannerpro.ProjectsList" /> <!-- Change the name to the context activity_projects_list.xml -->

                <category android:name="android.intent.category.DEFAULT" /> <!-- Change .LAUNCHER to .DEFAULT, since there should be only one launcher activity -->
            </intent-filter>
        </activity>

    </application>

</manifest>

请帮我解决这个问题。谢谢!

PS: Instant Run已停用。即使启用了相同的错误

更新:以下是Register.java代码:

package com.planner.reemshams.projectplannerpro;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Register extends AppCompatActivity {

    //private EditText email_id = (EditText) findViewById(R.id.email_id);
    //private EditText password = (EditText) findViewById(R.id.password);

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        Button register_btn = (Button) findViewById(R.id.register_btn); 

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        register_btn.setOnClickListener(
                new View.OnClickListener() {

                    @Override
                    public void onClick(View view){
                        // Start NewActivity.class
                        Intent myIntent = new Intent(Register.this,
                                ProjectsList.class);
                        startActivity(myIntent);

                    }

                }
        );
    }
}

0 个答案:

没有答案