1
votes

I created an Android project in Eclipse using File->New->Android Project. I created an Android virtual device of the same API version 10 (2.3.3). I created an activity Asdf in package foo.foo.foo

Android projects are not supposed to have a main function, so why is Java looking for one?

package foo.foo.foo;

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

public class Asdf extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Exception in thread "main" java.lang.NoClassDefFoundError: Caused by: java.lang.ClassNotFoundException: at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: . Program will exit.

Edit: the activity is declared in the manifest, which is also auto-generated by eclipse:

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Asdf"
                  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>
1

1 Answers

2
votes

"main" is the layout file which will be created by default at app creation. You might have deleted that layout from layout folder or might have changed it name in layout folder. If you had designed any layout then refer it here. while main is not complusary.

Also have you declared your activity in manifeast file?

setContentView(R.layout.main); mean that it is loking for layout file to display rather then a function