java.lang.RuntimeException android

时间:2015-09-08 11:08:03

标签: java android eclipse

当我试图启动我的App In Genymotion时,我收到以下错误:

09-08 07:03:12.697: E/AndroidRuntime(2291): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.waddapp/com.example.waddapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.waddapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.waddapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.os.Looper.loop(Looper.java:135)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.ActivityThread.main(ActivityThread.java:5254)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at java.lang.reflect.Method.invoke(Native Method)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at java.lang.reflect.Method.invoke(Method.java:372)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
09-08 07:03:12.697: E/AndroidRuntime(2291): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.waddapp.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.waddapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
09-08 07:03:12.697: E/AndroidRuntime(2291):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
09-08 07:03:12.697: E/AndroidRuntime(2291):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
09-08 07:03:12.697: E/AndroidRuntime(2291):     ... 10 more
09-08 07:03:12.697: E/AndroidRuntime(2291):     Suppressed: java.lang.NoClassDefFoundError: com.example.waddapp.MainActivity
09-08 07:03:12.697: E/AndroidRuntime(2291):         at dalvik.system.DexFile.defineClassNative(Native Method)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at dalvik.system.DexFile.defineClass(DexFile.java:226)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at dalvik.system.DexPathList.findClass(DexPathList.java:321)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
09-08 07:03:12.697: E/AndroidRuntime(2291):         ... 14 more
09-08 07:03:12.697: E/AndroidRuntime(2291):     Suppressed: java.lang.ClassNotFoundException: com.example.waddapp.MainActivity
09-08 07:03:12.697: E/AndroidRuntime(2291):         at java.lang.Class.classForName(Native Method)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
09-08 07:03:12.697: E/AndroidRuntime(2291):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
09-08 07:03:12.697: E/AndroidRuntime(2291):         ... 13 more
09-08 07:03:12.697: E/AndroidRuntime(2291):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

为什么找不到我的班级?

这是我的代码:

package com.example.waddapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphUser;

public class MainActivity extends ActionBarActivity {
    // Create, automatically open (if applicable), save, and restore the 
    // Active Session in a way that is similar to Android UI lifecycles. 
    private UiLifecycleHelper uiHelper;
    private View otherView;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Set View that should be visible after log-in invisible initially
        otherView = (View) findViewById(R.id.other_views);
        otherView.setVisibility(View.GONE);
        // To maintain FB Login session
        uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);
    }

    // Called when session changes
    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    // When session is changed, this method is called from callback method
    private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {
        final TextView name = (TextView) findViewById(R.id.name);
        final TextView gender = (TextView) findViewById(R.id.gender);
        final TextView location = (TextView) findViewById(R.id.location);
        // When Session is successfully opened (User logged-in)
        if (state.isOpened()) {
            Log.i(TAG, "Logged in...");
            // make request to the /me API to get Graph user
            Request.newMeRequest(session, new Request.GraphUserCallback() {

                // callback after Graph API response with user
                // object
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        // Set view visibility to true
                        otherView.setVisibility(View.VISIBLE);
                        // Set User name 
                        name.setText("Hello " + user.getName());
                        // Set Gender
                        gender.setText("Your Gender: "
                                + user.getProperty("gender").toString());
                        location.setText("Your Current Location: "
                                + user.getLocation().getProperty("name")
                                        .toString());
                    }
                }
            }).executeAsync();
        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
            otherView.setVisibility(View.GONE);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        uiHelper.onActivityResult(requestCode, resultCode, data);
        Log.i(TAG, "OnActivityResult...");
    }

    @Override
    public void onResume() {
        super.onResume();
        uiHelper.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }
}

我是Java编程和Android开发的新手,所以所有的帮助都会受到赞赏。

下面你可以从我的项目中找到我的manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.waddapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.facebook.LoginActivity"
            android:theme="@style/AppTheme">
        </activity>
    </application>

</manifest>

3 个答案:

答案 0 :(得分:1)

你的logcat抛出什么

 java.lang.ClassNotFoundException: Didn't find class "com.example.waddapp.MainActivity" 

ClassLoader 找不到报告的类时,抛出 ClassNotFoundException 。这通常意味着 CLASSPATH 中缺少该类。

你应该做什么

请修改清单。

答案 1 :(得分:0)

您是否在清单文件中提到了活动标签?

 <activity
        android:name=".MainActivity >
        <intent-filter android:label="@string/app_name" >
            <action android:name="android.intent.action.MAIN" />

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

答案 2 :(得分:0)

你的Facebook活动应该从他们的文档中声明这样,但是这样就可以解决问题了。 <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" />