无法实例化的活动......引起的ClassNotFoundException的 [英] Unable to instantiate activity... Caused by ClassNotFoundException

查看:271
本文介绍了无法实例化的活动......引起的ClassNotFoundException的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将一个完美的工作应用程序库(包括Activity类!),我试图创建使用整个库通过简单的超类图书馆的活动申请后:

After converting a perfectly working application to a library (including its Activity class!), I am trying to create an application that uses that entire library by simply superclassing the library's activity:

package com.example.baseapp.paid;

import android.os.Bundle;
import com.example.baseapp.LibActivity;


public class PaidActivity extends LibActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}

Eclipse构建这个新重新构建应用程序没有任何错误,但是当我尝试运行它,我得到一个异常:

Eclipse builds this newly "re-architected" application without any errors, but when I try to run it, I get an exception:

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

我不知道为什么会这样,因为对于错误找不到类上课的时候​​是完全建立在派生类(没有错误!),现在试图运行。

I have no idea why this is happening since the error for "Class Not Found" when the class is exactly the derived class built (without errors!) and now trying to run.

我要如何解决呢?

我在想什么?

修改(由@CaspNZ答题):

EDIT (answering question by @CaspNZ):

这是库项目的Andr​​oidManifest.xml中:

This is the AndroidManifest.xml of the library project:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.baseapp"
      android:versionCode="5"
      android:versionName="1.1.2"> 
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET"/>   
</manifest>

这是应用程序的Andr​​oidManifest.xml中,使用库项目:

And this is the AndroidManifest.xml of the application, using the library project:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.baseapp.paid"
      android:versionCode="5"
      android:versionName="1.1.2"> 
    <uses-sdk android:minSdkVersion="8" />
    <uses-library android:name="AppLibrary" />

    <uses-permission android:name="android.permission.INTERNET"/>   

    <application android:icon="@drawable/icon">
        <activity android:name=".PaidActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.baseapp.LibActivity" android:label="com.example.baseapp.LibActivity:string/rx_label">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="EditPreferences" 
                android:label="com.example.baseapp.LibActivity:string/app_name">
        </activity>
    </application>
</manifest>

我会AP preciate任何暗示试图解决这个,因为这是我第一次尝试使用一个库项目,我不熟悉的招数参与得到这个工作。

I would appreciate any hint trying to troubleshoot this as this is my first time ever trying to use a library project and I am not familiar with the "tricks" involved to get this working.

推荐答案

我终于解决了这个问题。事实证明,我在两个项目的属性2关键设置,设置不正确:

I finally solved the problem. It turns out that I had 2 critical settings in the Properties of both projects not set correctly:

  1. 在库项目,是图书馆 是的不可以检查出于某种原因。 我可以发誓,我查了一下,但 知道如何异想天开了Android 在开发环境 Eclipse可以的话,我怀疑它 在未选中的Eclipse(或ADT 插件),因为一些小故障的结果。
  2. 在应用程序项目,我 忘了加我的库项目 作为通过参考添加... 按钮。 (我多么愚蠢的可能呢?)
  1. In the library project, "Is Library" was not checked for some reason. I could swear that I checked it, but knowing how whimsical the Android development environment under Eclipse can be, I suspect that it was unchecked by Eclipse (or the ADT plugin) as a result of some glitch.
  2. In the application project, I neglected to add my library project as a reference via the Add... button. (how dumb could I be?)

我希望其他新手像我一样会发现此信息是否有用。有时候,一个非常困难的问题进行调试,隐藏着一个配置错误时,无辜不知情强调程序员假定这已经是照顾......

I hope that other newbies like me will find this information helpful. Sometimes, an extremely difficult problem to debug, hides a configuration error when the innocent unsuspecting stressed programmer assumes that this is already has been taken care of...

这篇关于无法实例化的活动......引起的ClassNotFoundException的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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