我刚创建了一个简单的hello world程序,看起来所有代码都很好,但有些东西让android显示“不幸的应用程序需要关闭”错误
startingPoint.java代码,它是启动器类
package demo4;
import com.example.demo4.R;
import android.app.Activity;
import android.os.Bundle;
public class startingPoint extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xml,它是启动器类
的布局<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".startingPoint"
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>
这是logcat
08-30 12:46:22.921: D/AndroidRuntime(326): Shutting down VM
08-30 12:46:22.941: W/dalvikvm(326): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-30 12:46:23.021: E/AndroidRuntime(326): FATAL EXCEPTION: main
08-30 12:46:23.021: E/AndroidRuntime(326): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.demo4/com.example.demo4.startingPoint}: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.os.Looper.loop(Looper.java:123)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.reflect.Method.invokeNative(Native Method)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.reflect.Method.invoke(Method.java:507)
08-30 12:46:23.021: E/AndroidRuntime(326): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-30 12:46:23.021: E/AndroidRuntime(326): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-30 12:46:23.021: E/AndroidRuntime(326): at dalvik.system.NativeStart.main(Native Method)
08-30 12:46:23.021: E/AndroidRuntime(326): Caused by: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
08-30 12:46:23.021: E/AndroidRuntime(326): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
08-30 12:46:23.021: E/AndroidRuntime(326): ... 11 more
答案 0 :(得分:0)
很受欢迎......这是Mtoypc所表明的。包名称不同,并没有反映在startingPoint.java
中答案 1 :(得分:0)
所以我发表评论作为答案:)
似乎android尝试在您的包com.example.demo4.startingPoint
中找到该类,但在您的代码中,该包只是demo4
。尝试按package com.example.demo4.