Android的活动了ClassNotFoundException - 尝试一切 [英] Android Activity ClassNotFoundException - tried everything

查看:140
本文介绍了Android的活动了ClassNotFoundException - 尝试一切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚重构一个应用程序到一个框架库和应用程序,但现在当我试着开始在模拟器中,我得到了下面的错误堆栈跟踪应用程序:

I've just refactored an app into a framework library and an application, but now when I try and start the app in the emulator I get the following error stack trace:

06-02 18:22:35.529: E/AndroidRuntime(586): FATAL EXCEPTION: main
06-02 18:22:35.529: E/AndroidRuntime(586): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.matthewrathbone.eastersays/com.matthewrathbone.eastersays.EasterSimonSaysActivity}: java.lang.ClassNotFoundException: com.matthewrathbone.eastersays.EasterSimonSaysActivity in loader dalvik.system.PathClassLoader[/data/app/com.matthewrathbone.eastersays-1.apk]
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.os.Looper.loop(Looper.java:123)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 18:22:35.529: E/AndroidRuntime(586):  at java.lang.reflect.Method.invokeNative(Native Method)
06-02 18:22:35.529: E/AndroidRuntime(586):  at java.lang.reflect.Method.invoke(Method.java:521)
06-02 18:22:35.529: E/AndroidRuntime(586):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-02 18:22:35.529: E/AndroidRuntime(586):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-02 18:22:35.529: E/AndroidRuntime(586):  at dalvik.system.NativeStart.main(Native Method)
06-02 18:22:35.529: E/AndroidRuntime(586): Caused by: java.lang.ClassNotFoundException: com.matthewrathbone.eastersays.EasterSimonSaysActivity in loader dalvik.system.PathClassLoader[/data/app/com.matthewrathbone.eastersays-1.apk]
06-02 18:22:35.529: E/AndroidRuntime(586):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-02 18:22:35.529: E/AndroidRuntime(586):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-02 18:22:35.529: E/AndroidRuntime(586):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-02 18:22:35.529: E/AndroidRuntime(586):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
06-02 18:22:35.529: E/AndroidRuntime(586):  ... 11 more

通常这意味着清单文件是错误的,在某种程度上,但我已经双重检查一切我能想到的。

Usually this means that the manifest file is wrong in some way, but I've double checked everything I can think of.

下面是我的活动类:

package com.matthewrathbone.eastersays;

import android.os.Bundle;

import com.rathboma.simonsays.Assets.Season;
import com.rathboma.simonsays.SeasonPicker;
import com.rathboma.simonsays.SimonSaysActivity;

    public class EasterSimonSaysActivity extends SimonSaysActivity {

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

      @Override
      protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
      }

      @Override
      public SeasonPicker getSeasonPicker() {
       return new SeasonPicker(){
        @Override
        public Season getSeason() {
          // TODO Auto-generated method stub
          return Season.EASTER;
        }
       };
      }
    }

正如你所看到的,它的上市在正确的清单:

As you can see, it's listed correctly in the manifest:

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

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".EasterSimonSaysActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

我不知道如何解决这一问题,并且将AP preciate任何帮助。我已经扫描的就这么多类似的问题,没有看到这个特定的行为。

I have no idea how to fix this, and would appreciate any help. I've scanned many similar questions on SO without seeing this particular behavior.

更多信息:

  • 我已经生成APK内检查和类有一个条目 该classes.dex文件
  • 在我试过清洁/建设项目 日食
  • 在我使用的是全新的设备的图像不具有试过 在APK的上一个副本已
  • 在我的库项目变成 一个普通的Java,然后又变成一个Android项目,没有 差异
  • 添加抽象SimonSaysActivity到清单没什么区别。
  • 在我试图使每个依赖一个Android库项目,并同步他们需要的Andr​​oid版本,它并没有帮助
  • I've checked inside the generated APK and the class has an entry in the classes.dex file
  • I've tried cleaning/building the project in eclipse
  • I've tried using a totally new device image that doesn't have a copy of the APK on it already
  • I've changed the library project into a regular java, then changed back into an android project, no difference
  • Adding the abstract SimonSaysActivity to the manifest makes no difference.
  • I've tried making every dependency an android library project, and syncing the android version that they require, it did not help

实测值的溶液(见下文)。为了大家公布答案/评论:你所有的岩石,感谢您帮助我工作,通过问题

Found the solution (see below). To everyone that posted an answer / comment: You all rock, thanks for helping me work through the problems!

看起来这是一个由SDK工具升级推出。由于下面@Nick在该链接的评论: <一href="http://iqadd.com/item/noclassdeffounderror-adt-fix">http://iqadd.com/item/noclassdeffounderror-adt-fix

Looks like this is introduced by an SDK tools upgrade. Thanks to @Nick below in the comments for this link: http://iqadd.com/item/noclassdeffounderror-adt-fix

推荐答案

我用我自己的项目的一些时间玩了,我可以复制你的问题,并得到完全相同的异常堆栈跟踪尝试运行我的主要项目时, ,所以我觉得这可能是原因:

I spent some time play with my own project, and I am able to replicate your problem and get exactly the same exception stack trace when trying to run my main project, so I think this could be the cause:

就像我的想法,这是所有关于你如何引用您的Andr​​oid库项目在Android主体工程,一个简单的Eclipse配置设置。

Just like what I thought, it is all about how you reference your Android library project in the Android main project, a simple Eclipse configuration settings.

错误的方式:
右击主项目,选择属性 - &GT; Java构建路径 - &GT;项目 - &GT;添加... ,这个附加了Android库项目作为Android的主要项目的构建路径依赖的项目,这是行不通的。如果所有必需的Andr​​oid相关的资源,在主要项目中定义的,你不会得到任何错误在编译时,但是运行应用程序的时候,你在问题中描述的异常。

The Wrong Way:
Right click main project, choose Properties -> Java Build Path -> Projects -> Add..., this add the Android library Project as a dependency project in Android main project's build path, this does not work. If all required Android-related resources are defined in main project, you will not get any error at compile time, but when run the application, you get the exception described in the question.

的正确方法:
右击主项目,选择属性 - &GT;安卓,在图书馆部分,在这里添加你的Andr​​oid库项目。查看官方开发指南<一href="http://developer.android.com/guide/developing/projects/projects-eclipse.html#ReferencingLibraryProject">Referencing库项目。这应该可以解决所有的问题。另外请注意,你必须使用相对路径引用实际的Andr​​oid库项目,如图书馆计划说明 - 发展的考虑

The Correct Way:
Right click main project, choose Properties -> Android, in the Library section, add your Android library project here. Check out official dev guide Referencing a library project. This should fix all your problem. Also note that you have to use relative path reference the actual Android library project, as stated in the Library Project - Development considerations.

希望这有助于。

这篇关于Android的活动了ClassNotFoundException - 尝试一切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆