【问题标题】:NoClassDefFoundError (unknown source) when starting new Activity启动新 Activity 时出现 NoClassDefFoundError(未知来源)
【发布时间】:2013-11-19 11:54:08
【问题描述】:

我正在尝试开始一项活动

`package com.kapzlock.mytestproject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Splash extends Activity{

@Override
protected void onCreate(Bundle SomeVar) {
    // TODO Auto-generated method stub
    super.onCreate(SomeVar);
    setContentView(R.layout.splash);
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            }
            catch(InterruptedException e){
                e.printStackTrace();
            }
            finally{
                Intent openStartingPoint = new Intent("com.kapzlock.mytestproject.MAINACTIVITY");
                startActivity(openStartingPoint);
            }
        }
    };
    timer.start();
}

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

}

}
`

Manifest xml 文件如下所示:

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        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=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.kapzlock.mytestproject.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>

它编译没有问题,但是当我运行 Splash.class 时,我得到一个Exception in thread "main" java.lang.NoClassDefFoundError: android/app/Activity 错误。包名是 com.kapzlock.mytestproject,我引用的类是 MainActivity.class。有人知道错误可能出在哪里吗?

【问题讨论】:

  • 您是否导入任何其他 jar 文件?

标签: java android noclassdeffounderror


【解决方案1】:

试试这个:

转到 Project/Properties/Java Build Path/Order and Export -- 如果您使用它,请确保在 Android Dependencies 和支持库前面有一个检查。标记所有复选框。单击 Apply 并清理项目。

这对我有用。希望这会有所帮助。

【讨论】:

  • 谢谢。我试过了,但在尝试运行它时仍然遇到同样的错误。
  • 您是否导入任何其他 jar 文件?
  • 不,我没有,但由于我遇到了这个错误,我用 AVD 更改了一些设置(在阅读了我通过谷歌搜索找到的一些提示之后)。由于“清晰”,我什至现在体验到根 android 类显示编译错误(如 Activity 和 Button)。我的 Eclipse 和 Android SDK 的整个设置似乎是一个错误。
【解决方案2】:

用下面的代码替换你的代码

finally
{
   Intent openStartingPoint = new Intent(this,MAINACTIVITY.class);
   startActivity(openStartingPoint);
}

从 mainActivity 标记中的 manifest.xml 中删除以下内容

<intent-filter>
       <action android:name="com.kapzlock.mytestproject.MAINACTIVITY" />
       <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

【讨论】:

  • 感谢您的帮助。现在它显示构造函数 Intent() 未定义的错误。
  • 日志猫为空。我是编程新手,所以我不知道。控制台显示:线程“main”中的异常 java.lang.NoClassDefFoundError: android/app/Activity at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source)。
  • 显然,它在运行时找不到Class,但它曾经编译它。
猜你喜欢
  • 2011-06-14
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-14
  • 1970-01-01
相关资源
最近更新 更多