Hello Form Stuff-application中的问题无法在模拟器上运行

时间:2011-08-10 03:24:17

标签: android

我一直在尝试Android开发者网站中给出的“Form Stuff”示例。但是,在模拟器上,我不断收到应用程序意外停止工作的消息。我完全复制了网站上的代码,但这似乎正在发生。我做错了什么?

HelloFormStuff2.java:

package com.android.HelloLinearLayouts;

import android.app.Activity;
import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.Toast;

 public class HelloFormStuff2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            Toast.makeText(HelloFormStuff2.this, 
                           "Beep Bop", 
                           Toast.LENGTH_SHORT).show();
        }
    });

}

}

main.xml文件:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

 <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="@drawable/android_button" />
   </LinearLayout>

android_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/android_pressed"
      android:state_pressed="true" />
<item android:drawable="@drawable/android_focused"
      android:state_focused="true" />
<item android:drawable="@drawable/android_normal" />
</selector>

我该怎么办?

日志: 这就是最后发生的事情: -

08-10 09:30:15.335: DEBUG/AndroidRuntime(265): Shutting down VM
08-10 09:30:15.335: DEBUG/jdwp(265): adbd disconnected
08-10 09:30:15.405: INFO/AndroidRuntime(265): NOTE: attach of thread 'Binder Thread #3' failed
08-10 09:30:15.865: INFO/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x3462c8:0x3463d4] in 376387 ns
08-10 09:30:15.955: DEBUG/AndroidRuntime(277): Shutting down VM
08-10 09:30:15.955: WARN/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-10 09:30:16.024: ERROR/AndroidRuntime(277): FATAL EXCEPTION: main
08-10 09:30:16.024: ERROR/AndroidRuntime(277): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.HelloLinearLayouts/com.android.HelloLinearLayouts.HelloFormStuff2Activity}: java.lang.ClassNotFoundException: com.android.HelloLinearLayouts.HelloFormStuff2Activity in loader dalvik.system.PathClassLoader[/data/app/com.android.HelloLinearLayouts-1.apk]
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.os.Looper.loop(Looper.java:123)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at java.lang.reflect.Method.invoke(Method.java:521)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at dalvik.system.NativeStart.main(Native Method)
08-10 09:30:16.024: ERROR/AndroidRuntime(277): Caused by: java.lang.ClassNotFoundException: com.android.HelloLinearLayouts.HelloFormStuff2Activity in loader dalvik.system.PathClassLoader[/data/app/com.android.HelloLinearLayouts-1.apk]
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-10 09:30:16.024: ERROR/AndroidRuntime(277):     ... 11 more
08-10 09:30:16.117: WARN/ActivityManager(58):   Force finishing activity com.android.HelloLinearLayouts/.HelloFormStuff2Activity
08-10 09:30:16.355: INFO/ARMAssembler(58): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x3266a0:0x32675c] in 338074 ns
08-10 09:30:16.655: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44f9f440 com.android.HelloLinearLayouts/.HelloFormStuff2Activity}
08-10 09:30:27.147: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44f9f440 com.android.HelloLinearLayouts/.HelloFormStuff2Activity}
08-10 09:35:06.196: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
08-10 09:35:16.209: INFO/Process(277): Sending signal. PID: 277 SIG: 9
08-10 09:35:16.235: INFO/ActivityManager(58): Process com.android.HelloLinearLayouts (pid 277) has died.
08-10 09:35:16.385: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450655e0

1 个答案:

答案 0 :(得分:0)

您可以通过查看LogCat视图并确定导致应用程序崩溃的原因来开始。如果您仍然无法弄明白,请在此处发布logcat内容。