2016-06-11 111 views
-1

当我跑我的AVD的应用程序,它提供了错误:安卓:不幸的是,MyApp的已停止

Unfortunately, MyApp has stopped.

当我看到日志的猫,它看起来像这样:

登录猫第一节

enter image description here

登录猫第二部分

enter image description here

这里是我的MainActivity文件:

package com.ghani.myapp; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

}

这是我activity_main文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.ghani.myapp.MainActivity" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

+0

发布您的代码会抛出异常。 –

+0

也许这可以帮助你http://stackoverflow.com/a/24587320/2442831 – Lino

+0

谢谢@林诺,这个链接帮了我。 –

回答

-1

请勿使用API​​ Level 20和Platform 4.4W作为Android虚拟设备。在ADV上设置Level 19和Platform 4.2.2时,所有操作都应该如此。

+0

为什么? API Level 20有什么问题?你怎么知道这是造成这个问题的原因? – Egor

+0

可用的AVD版本与通过SDK管理器安装的系统映像绑定。 –

+0

是的,我知道,但它是如何适用于手头的问题? – Egor

0

您针对的版本是Android Wear特定API,因此它会在手机上导致错误。尝试将API更改为21或19,并且一切都应该启动并运行。

如果你的目标的Android Wear设备,然后尝试改变

android:theme="@style/AppTheme" > 

android:theme="@android:style/Theme.DeviceDefault" >