我是Android的新手,但对Java来说还不错,更喜欢Netbeans和Eclipse。我试图让HelloAndroid应用程序运行,但没有成功。
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。但是当我尝试运行它时,我得到了可怕的“应用程序HelloAndroid(进程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
y@451f4560
我花了好几天努力完成这项工作......安装了Netbeans的新副本,重新安装了NBAndroid,重新安装了Android SDK,Google搜索并使用了代码。有人可以帮忙吗?
由于
谢
答案 0 :(得分:0)
该项目似乎运行良好。我使用了你的Activity和manifest,没有任何问题。尝试清理您的项目。转到项目 - &gt;清理
答案 1 :(得分:0)
setContentView(R.layout.main);
放置你的main.xml。使用DroidDraw创建main.xml并调用setContentView(R.layout.main);
而不是setContentView(tv);