我开发了自己的应用程序并尝试在模拟器5556中打开它。它已成功安装。 但是当我打开它时,它会立即关闭。我希望有人能帮帮忙。 这是我的androidmainfest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.monkey"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:glEsVersion="0x20000" android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCi43x8rh1xwonf15SQ2faHLPKCJUkzAn8" />
<activity android:theme="@*android:style/Theme.NoTitleBar" android:label="@string/app_name" android:name="com.example.monkey.Home" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.monkey.SettingPreferences" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.CategoryList" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.MenuList" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.MenuDetail" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.ShareMenu" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.Contact" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.News" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.NewsDetail" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.YourOrder" android:screenOrientation="portrait" />
<activity android:name="com.example.monkey.Reservation" android:screenOrientation="portrait" />
</application>
03-16 13:01:14.249: D/AndroidRuntime(1138): Shutting down VM
03-16 13:01:14.249: W/dalvikvm(1138): threadid=1: thread exiting with uncaught exception (group=0xb3a3aba8)
03-16 13:01:14.419: E/AndroidRuntime(1138): FATAL EXCEPTION: main
03-16 13:01:14.419: E/AndroidRuntime(1138): Process: com.example.monkey, PID: 1138
03-16 13:01:14.419: E/AndroidRuntime(1138): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.monkey/com.example.monkey.Home}: java.lang.ClassNotFoundException: Didn't find class "com.example.monkey.Home" on path: DexPathList[[zip file "/data/app/com.example.monkey-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.monkey-2, /system/lib]]
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.os.Looper.loop(Looper.java:136)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-16 13:01:14.419: E/AndroidRuntime(1138): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 13:01:14.419: E/AndroidRuntime(1138): at java.lang.reflect.Method.invoke(Method.java:515)
03-16 13:01:14.419: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-16 13:01:14.419: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-16 13:01:14.419: E/AndroidRuntime(1138): at dalvik.system.NativeStart.main(Native Method)
03-16 13:01:14.419: E/AndroidRuntime(1138): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.monkey.Home" on path: DexPathList[[zip file "/data/app/com.example.monkey-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.monkey-2, /system/lib]]
03-16 13:01:14.419: E/AndroidRuntime(1138): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-16 13:01:14.419: E/AndroidRuntime(1138): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-16 13:01:14.419: E/AndroidRuntime(1138): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
03-16 13:01:14.419: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
03-16 13:01:14.419: E/AndroidRuntime(1138): ... 11 more
答案 0 :(得分:1)
好吧,根据错误日志,它找不到您活动的java代码。您是否使用IDE生成活动?请确保用于您的活动的类具有相同的名称。在您的情况下,您必须在src文件夹中有一个名为Home.java
的文件。你能确认它在那里吗?
更新:如果您无法让IDE为您的活动生成代码,请尝试制作一个名为Home.java的文件并尝试以下代码:
import android.os.Bundle;
import android.app.Activity;
public class Home extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Home);
}
}
(请记住,最好的命名实践表明android中的布局名称为:全部为小写,通常以“activity”开头,而对于单词之间的空格使用“_”。这不是一个大问题,但它是良好的编码实践。好运!