我是Android的新手,但對於Java而言還行,並且更喜歡Netbeans到Eclipse。我試圖讓HelloAndroid應用程序運行,但沒有成功。Android和Netbeans:「意外停止」
package com.ex.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ex.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" >
<activity android:name="HelloAndroid"
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>
這編譯OK,並在仿真器和我的手機都安裝OK。但是當我嘗試運行它時,我遇到了可怕的「應用程序HelloAndroid(process com.ex.helloandroid)意外停止了,請重試。」
這裏的logcat的:
I/ActivityManager( 70): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ex.helloandroid/.HelloAndroid }
I/ActivityManager( 70): Start proc com.ex.helloandroid for activity com.ex.helloandroid/.HelloAndroid: pid=691 uid=10036 gids={1015}
D/AndroidRuntime( 691): Shutting down VM
W/dalvikvm( 691): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 691): FATAL EXCEPTION: main
E/AndroidRuntime( 691): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ex.helloandroid/com.ex.helloandroid.HelloAndroid}: java.lang.ClassNotFoundException: com.ex.helloandroid.HelloAndroid in loader dalvik.system.PathClassLoader[/dat
a/app/com.ex.helloandroid-1.apk]
E/AndroidRuntime( 691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
E/AndroidRuntime( 691): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 691): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 691): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 691): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 691): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 691): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 691): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 691): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 691): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 691): Caused by: java.lang.ClassNotFoundException: com.ex.helloandroid.HelloAndroid in loader dalvik.system.PathC
lassLoader[/data/app/com.ex.helloandroid-1.apk]
E/AndroidRuntime( 691): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 691): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 691): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 691): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
E/AndroidRuntime( 691): ... 11 more
W/ActivityManager( 70): Force finishing activity com.ex.helloandroid/.HelloAndroid
W/ActivityManager( 70): Activity pause timeout for HistoryRecord{45422d20 com.ex.helloandroid/.HelloAndroid}
W/ActivityManager( 70): Activity destroy timeout for HistoryRecord{45422d20 com.ex.helloandroid/.HelloAndroid}
I/Process ( 691): Sending signal. PID: 691 SIG: 9
I/ActivityManager( 70): Process com.ex.helloandroid (pid 691) has died.
W/InputManagerService( 70): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Prox
[email protected]
我花了幾天的時間,使這項工作...安裝了NetBeans的新副本,重新安裝NBAndroid,重新安裝Android SDK中,Google搜索與代碼撥弄。有人可以幫忙嗎?
感謝
弗蘭克
對不起,我應該說我正在嘗試將Java庫鏈接到Android項目,並將我的源代碼退回到了香草HelloAndroid。但沒有從Android項目中移除該庫。所以看起來這個問題與將Java庫項目鏈接到Android應用程序有關...即使該應用程序沒有在庫中使用任何東西,它存在的事實也會導致應用程序崩潰。 – user998303 2012-04-14 07:22:30