【问题标题】:Android App won't display in Android Studio EmulatorAndroid 应用程序不会在 Android Studio 模拟器中显示
【发布时间】:2014-03-07 06:58:22
【问题描述】:

我对 Android 开发非常陌生。我试图重新创建一个应用程序,如果您按下一个按钮,则会显示一条消息“新文本字符串”。但是,当我运行 AVD 并选择虚拟设备时,它不会显示它。只是我拥有的一个旧 TestApp。任何人都可以建议修复吗?我真的很感激。 我的代码:

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

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


<Button android:id="@+id/trigger"
    android:layout_width="100dip" android:layout_height="100dip"
    android:text="@string/button1"
    android:layout_below="@+id/hello_text"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="111dp" />
 </RelativeLayout>

SimpleActivity.java

package com.example.simpleactivityexample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.*;
import android.view.View;
public class SimpleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
    Button startButton = (Button) findViewById(R.id.trigger);
    startButton.setOnClickListener(new View.OnClickListener()
    {
        private TextView tv = (TextView) findViewById(R.id.hello_text);
        public void onClick(View view)
        {
            tv.setText("new text string");
        }
    }
    );

}
@Override
protected void onStart() {
    super.onStart();
    Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
    super.onResume();
    Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
}
@Override
protected void onRestart() {
    super.onRestart();
    Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
    Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
    super.onPause();
}
@Override
protected void onStop() {
    Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
    super.onStop();
}
@Override
protected void onDestroy() {
    Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
    super.onDestroy();
}


}

清单

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

<application
    android:debuggable="true"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.simpleactivityexample.SimpleActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  </application>

 </manifest>

字符串.xml

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 <string name="app_name">Dietary Application</string>
 <string name="hello">Hello!</string>
 <string name="button1">This is a button!</string>
 </resources>

【问题讨论】:

  • 我真的很抱歉布局不好,我对此完全陌生。
  • 由于问题不在您的代码中,您可能应该发布控制台输出。
  • C:\Android\sdk\tools\emulator.exe -avd AVD_for_Nexus_S_by_Google -netspeed full -netdelay none 设备已连接:emulator-5554 设备在线:emulator-5554 目标设备:AVD_for_Nexus_S_by_Google 上传本地路径:C: \Androd\AndroidStudioProjects\SimpleActivityExample\SimpleActivityExample\build\apk\SimpleActivityExample-debug-unaligned.apk 远程路径:/data/local/tmp/com.example.simpleactivityexample 安装 com.example.simpleactivityexample DEVICE SHELL 命令:pm install -r " /data/local/tmp/com.example.simpleactivityexample" 错误:无法访问包管理器。系统正在运行吗?

标签: java android android-intent


【解决方案1】:

我设法解决了。顺便说一下,我正在使用 Android Studio。 我转到屏幕顶部的运行选项卡并进入“编辑配置”。然后我勾选了“显示选择器对话框”。我启动了 AVD,当它完全启动时,A 按下了运行功能(绿色三角形),它在 Android 上启动。非常感谢所有帮助过的人!

【讨论】:

    【解决方案2】:

    您的代码看起来不错;当您单击“作为 Android 应用程序运行”时检查 logcat 和控制台输出以查看安装是否正常。

    Logcat 位于顶部菜单下

    Window-显示视图-其他-Android-Logcat

    还可以尝试清理项目并重新启动模拟器;此外,如果模拟器加载时应用没有显示,请尝试不退出模拟器再次运行它。

    【讨论】:

    • 我用的是Android Studio,找不到logcat。
    • @user3388470 尝试安装时您的模拟器可能不在线;尝试等待模拟器完全启动,然后从菜单中选择模拟设备,然后安装(先升级你的 AS)。
    【解决方案3】:

    您使用的是最新的工作室吗?好像是个老虫子

    Error when running emulator in Android Studio

    尝试等待模拟器启动,然后运行项目。

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 2020-12-27
      • 2016-09-24
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 2012-05-26
      相关资源
      最近更新 更多