2

I'm trying to start an activity

`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

}

}
`

The Manifest xml file looks like this:

<?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>

It compiles without problems, but when I run the Splash.class, I'm getting an Exception in thread "main" java.lang.NoClassDefFoundError: android/app/Activity Error. The package name is com.kapzlock.mytestproject and the class that I'm referencing to is MainActivity.class. Has anybody an idea where the mistake could be in?

1
  • Do you import any additional jar file? Nov 19, 2013 at 12:21

2 Answers 2

0

Try this:

Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it.Mark all checkboxes.Click on Apply and clean the project.

This worked for me.Hope this helps.

3
  • Thanks. I tried it, but I'm still having the same error when trying to run it.
    – KapzLock
    Nov 19, 2013 at 12:45
  • Do you import any additional jar file? Nov 19, 2013 at 12:48
  • No I didn't, but since I experienced this error, I changed some settings with the AVD (after reading some tips that I found by searching on google). Since the 'clear' I even experience now that root android classes show a compile error (like Activity and Button). It seems to be an error with the whole setup of my Eclipse and Android SDK.
    – KapzLock
    Nov 19, 2013 at 14:04
0

Replace your code with following

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

Remove following from your manifest.xml in mainActivity tag

<intent-filter>
       <action android:name="com.kapzlock.mytestproject.MAINACTIVITY" />
       <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
3
  • Thanks for your help. Now it shows an error that the constructor Intent() is undefined.
    – KapzLock
    Nov 19, 2013 at 12:21
  • The log cat is empty. I'm new into programming, so I don't have a clue. The console shows this: Exception in thread "main" java.lang.NoClassDefFoundError: android/app/Activity at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source).
    – KapzLock
    Nov 19, 2013 at 12:39
  • Apparently, it can't find the Class on runtime, but it used to compile it.
    – KapzLock
    Nov 19, 2013 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.