2012-03-30 174 views
0

我是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搜索与代码拨弄。有人可以帮忙吗?

感谢

弗兰克

回答

0

该项目看上去一切正常。我用你的活动和清单,没有问题。尝试清理你的项目。 GO到项目 - >清洁

+0

对不起,我应该说我正在尝试将Java库链接到Android项目,并将我的源代码退回到了香草HelloAndroid。但没有从Android项目中移除该库。所以看起来这个问题与将Java库项目链接到Android应用程序有关...即使该应用程序没有在库中使用任何东西,它存在的事实也会导致应用程序崩溃。 – user998303 2012-04-14 07:22:30

0
setContentView(R.layout.main); 

把你的main.xml。使用DroidDraw创建main.xml并拨打电话setContentView(R.layout.main);而不是setContentView(tv);