我无法在android studio仿真器屏幕上查看我的应用程序

时间:2015-04-10 05:38:03

标签: android android-emulator

我无法在android studio仿真器屏幕上查看我的应用程序。我曾尝试使用GPU主机,增加Ram,固定HAXM,固定英特尔VT-X。我认为问题可能在于我的代码。因为我是android和java的新手。我还将包括java文件和xml文件。我尝试重新启动,减少API级别等。 android logcat也附加了。这个应用程序试图添加两个数字。

java代码:

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity{


    Button add;
    TextView ans;
    EditText n1, n2;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_main);
        add = (Button) findViewById(R.id.button1);
        ans = (TextView) findViewById(R.id.textView1);
        n1 = (EditText) findViewById(R.id.editText1);
        n2 = (EditText) findViewById(R.id.editText2);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int a,b,c;
                a = Integer.parseInt(n1.getText().toString());
                b = Integer.parseInt(n2.getText().toString());
                c = a+b;
                ans.setText(""+c);

            }
        });
    }

}

xml代码:

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:id="@+id/layout1">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned"
        android:ems="10"
        android:id="@+id/editText1"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="50dp"
        android:layout_marginStart="50dp"
        android:layout_marginTop="35dp"
        android:layout_alignParentEnd="true"
        android:gravity="right" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned"
        android:ems="10"
        android:id="@+id/editText2"
        android:layout_below="@+id/editText1"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignStart="@+id/editText1"
        android:layout_marginTop="32dp"
        android:gravity="right" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SUM"
        android:id="@+id/button1"
        android:layout_below="@+id/editText2"
        android:layout_alignLeft="@+id/editText2"
        android:layout_alignStart="@+id/editText2"
        android:layout_marginTop="35dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="0"
        android:id="@+id/textView1"
        android:layout_below="@+id/button1"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignStart="@+id/button1"
        android:layout_marginTop="43dp" />
</RelativeLayout>

android logcat:

04-10 04:01:54.310    2143-2159/com.tandh.myfirstapp D/OpenGLRenderer﹕ Render dirty regions requested: true
04-10 04:01:54.310    2143-2143/com.tandh.myfirstapp D/﹕ HostConnection::get() New Host Connection established 0x7f10fcffae80, tid 2143
04-10 04:01:54.410    2143-2143/com.tandh.myfirstapp D/Atlas﹕ Validating map...
04-10 04:01:54.450    2143-2159/com.tandh.myfirstapp D/﹕ HostConnection::get() New Host Connection established 0x7f10fcffb3c0, tid 2159
04-10 04:01:54.480    2143-2159/com.tandh.myfirstapp I/OpenGLRenderer﹕ Initialized EGL, version 1.4
04-10 04:01:54.500    2143-2159/com.tandh.myfirstapp D/OpenGLRenderer﹕ Enabling debug mode 0
04-10 04:01:54.550    2143-2159/com.tandh.myfirstapp **W/EGL_emulation﹕ eglSurfaceAttrib not implemented**
04-10 04:01:54.550    2143-2159/com.tandh.myfirstapp **W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f10fcffe700, error=EGL_SUCCESS**

清单代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tandh.myfirstapp" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:1)

您需要确保拥有必要的 ARM EABI v7a系统映像和目标API的 Android SDK 。例如,如果您正在为API 15开发应用程序,则需要检查您是否拥有系统映像和API 15的SDK。