2016-06-21 69 views
0

我們寫信,現在跟蹤幾個Mobilephone傳感器我試圖編譯的時候,突然這個happend爲什麼這段代碼似乎找不到MainActivity?

E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.example.max.pswi, PID: 14291 
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.max.pswi/com.example.max.pswi.MainActivity}: 
java.lang.ClassNotFoundException: Didn't find class "com.example.max.pswi.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.max.pswi-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2555) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) 
at android.app.ActivityThread.access$900(ActivityThread.java:177) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:5951) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.max.pswi.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.max.pswi-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
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 android.app.Instrumentation.newActivity(Instrumentation.java:1079) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2545) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)  
at android.app.ActivityThread.access$900(ActivityThread.java:177)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)  
at android.os.Handler.dispatchMessage(Handler.java:102)  
at android.os.Looper.loop(Looper.java:145)  
at android.app.ActivityThread.main(ActivityThread.java:5951)  
at java.lang.reflect.Method.invoke(Native Method)  
at java.lang.reflect.Method.invoke(Method.java:372)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)  
Suppressed: java.lang.ClassNotFoundException: com.example.max.pswi.MainActivity 
at java.lang.Class.classForName(Native Method) 
at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
... 13 more 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

我不知道爲什麼這個錯誤發生在Android Studio中

進出口編程代碼的基於Android的應用

繼承人在MainActivity碼創建的錯誤:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    setContentView(R.layout.activity_main); 

    int currentVersionCode = 0; 

    try { 
     currentVersionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode; 
    } catch (PackageManager.NameNotFoundException e1) { 
     e1.printStackTrace(); 
    } 
    final ImageButton export = (ImageButton) findViewById(R.id.export); 
    final ImageButton clear = (ImageButton) findViewById(R.id.clear); 
    final ToggleButton toggle = (ToggleButton) findViewById(R.id.anaus); 
    final ImageButton settingsBtn = (ImageButton) findViewById(R.id.settings); 
    final ImageButton aktualisieren = (ImageButton) findViewById(R.id.aktualisieren); 
    final ListView liste = (ListView)findViewById(R.id.infos); 
    if (CheckIfServiceIsRunning()) 
     toggle.setChecked(true); 
    Boolean status = CheckIfServiceIsRunning(); 
    aktualisieren.setVisibility(View.VISIBLE); 
    export.setVisibility(View.VISIBLE); 
    toggle.setVisibility(View.VISIBLE); 
    settingsBtn.setVisibility(View.VISIBLE); 
    /* clear.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      SensorManager.getInstance().clearValues(SensorManager.getInstance().getContext()); 
     } 
    }); 
    export.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      SensorManager.getInstance().exportValues(SensorManager.getInstance().getContext()); 
     } 
    }); 
    settingsBtn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); 
      startActivity(intent); 
     } 
    }); 
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     Boolean status = CheckIfServiceIsRunning(); 
     ComponentName cn = new ComponentName(getApplicationContext(), NLService.class); 
     String flat = Settings.Secure.getString(getApplicationContext().getContentResolver(), "enabled_notification_listeners"); 
     final boolean enabled = (flat != null && flat.contains(cn.flattenToString())); 

     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      if (isChecked) { 
       // The toggle is enabled 
       if (!enabled) { 
        final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); 
        alertDialog.setCancelable(false); 
        alertDialog.setTitle("Notificationlistener aktivieren"); 
        alertDialog.setMessage("Bitte aktivieren sie den Notificationlistener für die App PSWI"); 
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Aktivieren", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          alertDialog.cancel(); 
          Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); 
          startActivity(intent); 
          Intent i = new Intent(getApplicationContext(), MainService.class); 
          i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
          getApplicationContext().startService(i); 
          status = true; 
         } 
        }); 
        alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "zurueck", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          alertDialog.cancel(); 
         } 
        }); 

        alertDialog.show(); 
       } else { 
        Intent i = new Intent(getApplicationContext(), MainService.class); 
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        getApplicationContext().startService(i); 
        status = true; 
       } 
      } else { 
       // The toggle is disabled 
       Intent i = new Intent(getApplicationContext(), MainService.class); 
       getApplicationContext().stopService(i); 
       status = false; 
      } 
     } 
    }); 
    // SensorManager.getInstance().populateListView(liste); 
    settings = PreferenceManager.getDefaultSharedPreferences(this); 
    if (settings.getBoolean("first_start", true)) { 
     // set initial version code, set first_start true and create ID 
     SharedPreferences.Editor editor = settings.edit(); 
     editor.putBoolean("first_start", false); 
     editor.putBoolean("SMSSensor:ObserverStarted", false); 
     editor.putString("CallSensor:lastIntent", null); 
     editor.putBoolean("serviceStarted", false); 
     editor.putString("version", "" + currentVersionCode); 
     editor.putString("ID", "" 
       + ((TelephonyManager) getApplicationContext() 
       .getSystemService(TELEPHONY_SERVICE)) 
       .getDeviceId().hashCode()); 
     editor.apply(); 
    } 
    // getLoaderManager().initLoader(0, null, (android.app.LoaderManager.LoaderCallbacks<Cursor>) this); 
    */ 
} 

我將b e很高興如果有人可以看看我越來越絕望

+0

你試過「清潔工程」和「同步工程與搖籃文件」也「重建工程」? –

回答

0

你在AndroidManifest文件中聲明瞭這個MainActivity嗎?

0

檢查AndroidManifest.xml

你應該可以看到你的活動application標籤內,像這樣:

<activity android:name="com.example.max.pswi.MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity>