开发者

Problem in Hello Form Stuff-application not working on emulator

I have been trying the "Form Stuff" example given in the android developer site. however, on the emulator I keep getting the message that the application has stopped working unexpectedly. I completely copied the code from the site, yet this seems to be happening. what am I doing wrong?

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();
        }
    });

}

}

the main.xml file:

 <?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>

what should i do?

log: this is what is happening in the end:-

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


You could start off by looking at the LogCat view and determining what caused the app crash. If you still cannot figure it out, please post the logcat contents here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜