Android:不幸的是,MyApp已经停止了

时间:2016-06-11 06:41:31

标签: android

当我在AVD上运行我的应用程序时,它会出错:

  

不幸的是,MyApp已经停止了。

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

Log Cat第一部分

enter image description here

Log Cat第二部分

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" />

2 个答案:

答案 0 :(得分:0)

您要定位的版本是Android Wear特定的API,因此会导致手机出错。尝试将API更改为21或19,所有内容都应该启动并运行。

如果您要定位Android Wear设备,请尝试更改

android:theme="@style/AppTheme" >

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

答案 1 :(得分:-1)

不要将API等级20和平台4.4W用作Android虚拟设备。在ADV上设置Level 19和Platform 4.2.2,一切都按预期运行。