找不到类和null对象引用异常

时间:2016-09-17 15:34:10

标签: android

我现在已经完成了所有脚本和设计,没有编译时错误但是没有出现这个运行时错误,我的应用程序闪烁而且没有启动。 我有它需要的所有文件,一切都完成了, 请立即建议,


这是我的MainActivity.java代码,可能会抛出这些异常

package com.example.dell.demologin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.HashMap;

import activity.LoginActivity;
import helper.SQLiteHandler;
import helper.SessionManager;

public class MainActivity extends Activity {

private TextView txtName;
private TextView txtEmail;
private Button btnLogout;
private SQLiteHandler db;
private SessionManager session;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);


    txtName = (TextView) findViewById(R.id.name);
    txtEmail = (TextView) findViewById(R.id.email);
    btnLogout = (Button) findViewById(R.id.btnLogout);

    // SqLite database handler
    db = new SQLiteHandler(getApplicationContext());

    // session manager
    session = new SessionManager(getApplicationContext());

    if (!session.isLoggedIn()) {
        logoutUser();
    }

    // Fetching user details from sqlite
    HashMap<String, String> user = db.getUserDetails();

    String name = user.get("name");
    String email = user.get("email");

    // Displaying the user details on the screen
    txtName.setText(name);
    txtEmail.setText(email);

    // Logout button click event
    btnLogout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            logoutUser();
        }
    });
}

/**
 * Logging out the user. Will set isLoggedIn flag to false in shared
 * preferences Clears the user data from sqlite users table
 * */
private void logoutUser() {
    session.setLogin(false);

    db.deleteUsers();

    // Launching the login activity
    Intent intent = new Intent(MainActivity.this, LoginActivity.class);
    startActivity(intent);
    finish();
}

}

这是我的logcat,


E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.dell.demologin, PID: 15578
  java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
      at android.app.LoadedApk.makeApplication(LoadedApk.java:601)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757)
      at android.app.ActivityThread.access$1600(ActivityThread.java:159)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:152)
      at android.app.ActivityThread.main(ActivityThread.java:5507)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
   Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
      at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:220)
      at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
      at android.app.Application.attach(Application.java:187)
      at android.app.Instrumentation.newApplication(Instrumentation.java:1001)
      at android.app.Instrumentation.newApplication(Instrumentation.java:985)
      at android.app.LoadedApk.makeApplication(LoadedApk.java:586)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
      at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:152) 
      at android.app.ActivityThread.main(ActivityThread.java:5507) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   Caused by: java.lang.ClassNotFoundException: com.example.dell.demologin.AppController
      at java.lang.Class.classForName(Native Method)
      at java.lang.Class.forName(Class.java:324)
      at java.lang.Class.forName(Class.java:285)
      at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
      at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
      at android.app.Application.attach(Application.java:187) 
      at android.app.Instrumentation.newApplication(Instrumentation.java:1001) 
      at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
      at android.app.LoadedApk.makeApplication(LoadedApk.java:586) 
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
      at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:152) 
      at android.app.ActivityThread.main(ActivityThread.java:5507) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
   Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.demologin.AppController" on path: DexPathList[[zip file "/data/app/com.example.dell.demologin-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dell.demologin-2/lib/arm64, /vendor/lib64, /system/lib64]]
      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
      at java.lang.Class.classForName(Native Method) 
      at java.lang.Class.forName(Class.java:324) 
      at java.lang.Class.forName(Class.java:285) 
      at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209) 
      at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
      at android.app.Application.attach(Application.java:187) 
      at android.app.Instrumentation.newApplication(Instrumentation.java:1001) 
      at android.app.Instrumentation.newApplication(Instrumentation.java:985) 
      at android.app.LoadedApk.makeApplication(LoadedApk.java:586) 
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4757) 
      at android.app.ActivityThread.access$1600(ActivityThread.java:159) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:152) 
      at android.app.ActivityThread.main(ActivityThread.java:5507) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
    Suppressed: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.demologin.AppController" on path: DexPathList[[dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-support-annotations-23.4.0_2f85958e3577c0887206665b958d529f2917b10d-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-mysql-connector-java_910883ba1d0637ad761451367a22e76261a44141-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-jtds_dd6bef0a517729fc55f6897f784dfc3379233a03-classes.dex", dex file "/data/data/com.example.dell.demologin/files/instant-run/dex/slice-internal_impl-23.4.0_acbefc0422230ccc1164ab
E/AndroidRuntime: Error reporting crash
  java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Application.getApplicationContext()' on a null object reference
      at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:96)
      at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
      at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
I/Process: Sending signal. PID: 15578 SIG: 9
Application terminated.

1 个答案:

答案 0 :(得分:0)

Google Play商店升级过程中的已知错误https://code.google.com/p/android/issues/detail?id=56296