我试图用eclipse和phonegap制作我的第一个应用程序。但是当我尝试运行应用程序时,我收到了这条消息:
06-26 20:50:03.736: E/AndroidRuntime(1449): FATAL EXCEPTION: main
06-26 20:50:03.736: E/AndroidRuntime(1449): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{my.first.app/my.first.app.MyFirstAppActivity}: java.lang.ClassNotFoundException: my.first.app.MyFirstAppActivity
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.os.Looper.loop(Looper.java:137)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-26 20:50:03.736: E/AndroidRuntime(1449): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 20:50:03.736: E/AndroidRuntime(1449): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 20:50:03.736: E/AndroidRuntime(1449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-26 20:50:03.736: E/AndroidRuntime(1449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-26 20:50:03.736: E/AndroidRuntime(1449): at dalvik.system.NativeStart.main(Native Method)
06-26 20:50:03.736: E/AndroidRuntime(1449): Caused by: java.lang.ClassNotFoundException: my.first.app.MyFirstAppActivity
06-26 20:50:03.736: E/AndroidRuntime(1449): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-26 20:50:03.736: E/AndroidRuntime(1449): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-26 20:50:03.736: E/AndroidRuntime(1449): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
06-26 20:50:03.736: E/AndroidRuntime(1449): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
06-26 20:50:03.736: E/AndroidRuntime(1449): ... 11 more
清单:
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<activity android:name=".MyFirstAppActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
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>
我完全按照http://docs.phonegap.com/en/1.8.1/guide_getting-started_index.md.html#Getting%20Started%20Guides
中的说明操作这是我的MyFirstAppActivity.java文件:
package my.first.app;
import android.app.Activity;
import android.os.Bundle;
import org.apache.cordova.*;
public class MyFirstAppActivity extends DroidGap { // DroidGap
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
和AndroidManifest.xml
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name=".MyFirstAppActivity" android:configChanges="orientation|keyboardHidden|screenSize" 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>
答案 0 :(得分:2)
您可能忘记在MyFirstAppActivity
中声明AndroidManifest.xml
。
确保您的清单在<application>
和</application>
标记之间包含类似内容:
<activity android:name=".MyFirstAppActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
答案 1 :(得分:0)
更改
public class MyFirstAppActivity extends DroidGap { // DroidGap
到
public class MyFirstAppActivity extends Activity {
并根据需要从那里创建DroidGap对象。