不幸的是应用程序已停止在Android模拟器中

时间:2012-07-18 10:39:13

标签: android relativelayout

我是android开发的新手。我正在使用Eclipse Helios和AVD 15.我正在尝试使用一个小程序Sliding Drawer。每当我想运行它时,编译器都没有显示错误,但是在Emulator中显示“不幸的是已经停止。我卸载它然后运行它几次,清理项目,消除每个警告它仍然会出现。当我在调试模式下运行它时,控制台示出了: -

[2012-07-18 12:03:34 - sliding drawer] ------------------------------
[2012-07-18 12:03:34 - sliding drawer] Android Launch!
[2012-07-18 12:03:34 - sliding drawer] adb is running normally.
[2012-07-18 12:03:34 - sliding drawer] Performing sliding.drawer.SlidingdrawerActivity 
activity launch
[2012-07-18 12:03:34 - sliding drawer] Automatic Target Mode: launching new emulator   compatible AVD 'And_em_1.5'
[2012-07-18 12:03:34 - sliding drawer] Launching a new emulator with Virtual Device  ![android debug image][1]'And_em_1.5'
[2012-07-18 12:03:54 - sliding drawer] New emulator found: emulator-5554
[2012-07-18 12:03:54 - sliding drawer] Waiting for HOME ('android.process.acore') to be launched...
[2012-07-18 12:05:33 - sliding drawer] HOME is up on device 'emulator-5554'
[2012-07-18 12:05:33 - sliding drawer] Uploading sliding drawer.apk onto device  'emulator-5554'
[2012-07-18 12:05:33 - sliding drawer] Installing sliding drawer.apk...
[2012-07-18 12:06:33 - sliding drawer] Success!
[2012-07-18 12:06:33 - sliding drawer] Starting activity  sliding.drawer.SlidingdrawerActivity on device emulator-5554
[2012-07-18 12:06:36 - sliding drawer] ActivityManager: Starting: Intent {  act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]  cmp=sliding.drawer/.SlidingdrawerActivity }
[2012-07-18 12:06:38 - sliding drawer] Attempting to connect debugger to  'sliding.drawer' on port 8633

我发送的代码:

.java文件

package sliding.drawer;

import android.app.Activity;
import android.os.Bundle;

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

main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"    >
     <SlidingDrawer
          android:id="@+id/drawer"
          android:layout_width="320dip"
          android:layout_height="440dip"
          android:orientation="vertical"
          android:handle="@+id/handle"
          android:content="@+id/content">
    <ImageView
          android:id="@+id/handle"
          android:layout_width="48dip"
          android:layout_height="48dip"
          android:contentDescription="@string/s"
          android:src="@drawable/ic_launcher" />
    <AnalogClock
          android:background="#D0A0A0"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" />
    </SlidingDrawer>

  <TextView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="@string/hello" />
</RelativeLayout>

然后一个窗口带有线程状态。

线程

ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1956    
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1981 
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 123    
ActivityThread$H.handleMessage(Message) line: 1147  
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 137 
ActivityThread.main(String[]) line: 4424    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not   available [native method]            
Method.invoke(Object, Object...) line: 511  
ZygoteInit$MethodAndArgsCaller.run() line: 784  
ZygoteInit.main(String[]) line: 551 
NativeStart.main(String[]) line: not available [native method]  

因为我是android新手,所以我很生气。请帮我。

谢谢..

3 个答案:

答案 0 :(得分:0)

我认为问题是您忘记了AnalogClock上的id属性:

<AnalogClock
    android:id="@+id/content"
    android:background="#D0A0A0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

答案 1 :(得分:0)

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

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <SlidingDrawer
        android:id="@+id/drawer"
        android:layout_width="320dp"
        android:layout_height="440dp"
        android:content="@+id/content"
        android:handle="@+id/handle"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/handle"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
             />

        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             >

            <AnalogClock
              android:background="#D0A0A0"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" />
        </RelativeLayout>
    </SlidingDrawer>

</RelativeLayout>

答案 2 :(得分:0)

在单独视图中使用模拟时钟

<RelativeLayout
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/ic_launcher" >

        <AnalogClock
          android:background="#D0A0A0"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" />
    </RelativeLayout>