0

我试图用 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>
4

2 回答 2

2

您可能忘记MyFirstAppActivity在您的AndroidManifest.xml.

<application>确保您的清单在and</application>标记之间包含类似这样的内容:

<activity android:name=".MyFirstAppActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
于 2012-06-26T20:53:44.660 回答
0

改变

public class MyFirstAppActivity extends DroidGap { // DroidGap

public class MyFirstAppActivity extends Activity { 

并在需要时从那里创建一个 DroidGap 对象。

于 2012-06-26T21:26:47.140 回答