我有一个我无法追踪的java.lang.ClassNotFoundException错误

时间:2014-07-17 05:29:47

标签: java android eclipse

我有一个应用程序,直到最近。 Google Play商店中的错误如下:

    java.lang.RuntimeException: Unable to instantiate application org.marsfirst.mars_app: java.lang.ClassNotFoundException: Didn't find class "org.marsfirst.mars_app" on path: DexPathList[[zip file "/data/app/org.marsfirst.mars_app-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.marsfirst.mars_app-2, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)
at android.app.ActivityThread.access$1600(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.marsfirst.mars_app" on path: DexPathList[[zip file "/data/app/org.marsfirst.mars_app-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.marsfirst.mars_app-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:981)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more

MainActivity:

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;//this gives me a warning that states its unused but it has been used in the past
import android.support.v4.app.Fragment;//this gives me a warning that states its unused but it has been used in the past

import android.app.Activity;//this gives me a warning that states its unused but it has been used in the past
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



import com.parse.ParseException;

import com.parse.ParseUser;

import com.parse.LogInCallback;

public class MainActivity extends ActionBarActivity {

    private String un, pw;
    public TextView username;
    public EditText pass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        username = (TextView) findViewById(R.id.editloginusername);
        pass = (EditText) findViewById(R.id.editpass);

        Button login = (Button) findViewById(R.id.login);
        login.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                un = username.getText().toString();
                pw = pass.getText().toString();

                ParseUser.logInInBackground(un, pw, new LogInCallback() {
                    public void done(ParseUser user, ParseException e) {
                        if (user != null) {
                            new CallMainPage().execute();

                        } else {
                            // username.setText("");
                            pass.setText("");
                            makeToast("User name or password not recognized.");

                        }

                    }
                });

            }
        });

        Button signup = (Button) findViewById(R.id.signup);
        signup.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                new CallSignup().execute();
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public class CallSignup extends AsyncTask<Void, Void, String> {
        protected String doInBackground(Void... urls) {
            Intent intent = new Intent(MainActivity.this, Signup.class);
            MainActivity.this.startActivity(intent);
            return "";
        }
    }

    public class CallMainPage extends AsyncTask<Void, Void, String> {
        protected String doInBackground(Void... urls) {
            Intent intent = new Intent(MainActivity.this, MainPage.class);
            MainActivity.this.startActivity(intent);
            return "";
        }
    }

    public void makeToast(String text) {
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(getApplicationContext(), text, duration);
        toast.show();
    }

}

我的清单:

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission
        android:name="org.marsfirst.mars_app"
        android:protectionLevel="signature" />

    <uses-permission android:name="org.marsfirst.mars_app" />

    <application
        android:name="org.marsfirst.mars_app"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="org.marsfirst.mars_app.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=".Signup"
            android:label="@string/signup"
            android:parentActivityName=".MainActivity" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".MainPage"
            android:label="Main Page" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Webpage"
            android:label="Website"
            android:parentActivityName=".MainPage" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainPage" />
        </activity>
        <activity
            android:name=".TeamNews"
            android:label="Team News"
            android:parentActivityName="org.marsfirst.mars_app.MainPage" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="org.marsfirst.mars_app.MainPage" />
        </activity>
        <activity
            android:name=".OprPage"
            android:label="OPR Page"
            android:parentActivityName="org.marsfirst.mars_app.MainPage" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="org.marsfirst.mars_app.MainPage" />
        </activity>
        <activity
            android:name="org.marsfirst.mars_app.MechPage"
            android:label="Mechanical Page"
            android:parentActivityName="org.marsfirst.mars_app.MainPage" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainPage" />
        </activity>
        <activity
            android:name=".DriveNews"
            android:label="Drive News"
            android:parentActivityName=".MainPage" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainPage" />
        </activity>
        <activity
            android:name=".ProgramingPage"
            android:label="Programming Page"
            android:parentActivityName=".MainPage" >
            <intent-filter />

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainPage" />
        </activity>

        <service android:name="com.parse.PushService" />

        <receiver android:name="com.parse.ParseBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="org.marsfirst.mars_app" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

文件资源管理器

http://imgur.com/UCwiJqP

我不确定是否是代码错误,由于我的研究,我认为这是一个构建路径错误但是我尝试过的所有内容似乎都失败请帮助 我将发布任何所需的附加屏幕截图或代码。在尝试解决问题时,我发现一个“修复”是将所有内容更改为android:name=".DriveNews"而不是android:name=org.marsfirst.mars_app.DriveNews这是最初的内容 感谢您提供任何帮助。

5 个答案:

答案 0 :(得分:0)

免责声明:我是Android开发中的菜鸟。

我想您要验证以下权限标记:

<permission
    android:name="org.marsfirst.mars_app"
    android:protectionLevel="signature" />

<uses-permission android:name="org.marsfirst.mars_app" />

类加载器无法找到类org.marsfirst.mars_app。从您的代码看来,mars_app似乎是一个包。与应用程序名称中的android:name相同。

答案 1 :(得分:0)

更改

android:name="org.marsfirst.mars_app"

android:name="org.marsfirst.mars_app.YourApplicationClass"

其中YourApplicationClass是扩展Application类的类。如果您没有任何此类,请删除name属性。

根据application标记的官方文档,name属性应为

The fully qualified name of an Application subclass implemented for the application. When the application process is started, this class is instantiated before any of the application's components.

The subclass is optional; most applications won't need one. In the absence of a subclass, Android uses an instance of the base Application class.

答案 2 :(得分:0)

可以显示文件浏览吗?

e.g。 it's is eclipse file explorer from web

答案 3 :(得分:0)

右键单击该项目 - &gt;构建路径 - &gt;配置构建路径 - &gt;订购和导出并检查您在项目中使用的库。

答案 4 :(得分:0)

您是否在申请中使用了proguard?

如果是:请从developer.google网站查看this。它可能会帮助你

  

默认的proguard.cfg文件试图涵盖一般情况,但是您可能会遇到异常,例如ClassNotFoundException,当ProGuard删除应用程序调用的整个类时会发生这种情况。

当ProGuard通过在proguard.cfg文件中添加-keep行来删除代码时,可以修复错误。例如:

-keep public class&lt; MyClass&gt;