【发布时间】:2014-07-09 17:50:28
【问题描述】:
我是 Android 开发新手(请善待),我尝试在两台不同的机器上设置我的开发环境,一台使用 AMD 处理器,另一台使用 Intel 处理器。在两台机器上,我都无法在模拟器中打开应用程序。我花了几个小时寻找问题,现在我需要帮助。
在我多说之前,我想提一下,在我安装 32 位 JDK 之前,eclipse 不会在我的机器上运行,即使我正在运行安装了 64 位 jdk 的 64 位机器。 (会不会跟这个有关系?)
请查看我的 imgur 链接以了解我在做什么。 Imgur Link
让我告诉你们我在做什么,你们可以告诉我我做错了什么。
在 Package Explorer 中,我右键单击,然后转到 New>Android Application Project。
然后我更改应用程序名称、包名称和所需的最低 SDK。
然后单击下一步,直到到达“创建活动”菜单,并选中“创建活动”旁边的框,然后选择“空白活动”。
然后我点击下一步,然后点击完成。
我认为这足以让我能够在模拟器中运行它,所以为了测试模拟器,我选择运行配置,选择我的应用程序,然后选择“com.johndavisdesign.helloworld.MainActivity。
我将目标设置为模拟运行 Android 4.4 的 Nexus 10 的 AVD。
这会启动模拟器,但不会安装程序,无论我等待多长时间。如果我在不关闭模拟器的情况下再次运行配置,程序将打开,但会显示“不幸的是,HelloWorld 已停止。”
我的控制台显示:
[2014-07-09 13:34:35 - HelloWorld] ------------------------------
[2014-07-09 13:34:35 - HelloWorld] Android Launch!
[2014-07-09 13:34:35 - HelloWorld] adb is running normally.
[2014-07-09 13:34:35 - HelloWorld] Performing com.johndavisdesign.helloworld.MainActivity activity launch
[2014-07-09 13:34:35 - HelloWorld] Automatic Target Mode: Preferred AVD 'Test' is not available. Launching new emulator.
[2014-07-09 13:34:35 - HelloWorld] Launching a new emulator with Virtual Device 'Test'
[2014-07-09 13:34:36 - Emulator] emulator: device fd:740
[2014-07-09 13:34:36 - Emulator]
[2014-07-09 13:34:36 - Emulator] HAX is working and emulator runs in fast virt mode
[2014-07-09 13:34:36 - Emulator] creating window 0 0 1640 1025
[2014-07-09 13:34:36 - Emulator] emulator: emulator window was out of view and was recentered
[2014-07-09 13:34:36 - Emulator]
[2014-07-09 13:34:36 - HelloWorld] New emulator found: emulator-5554
[2014-07-09 13:34:36 - HelloWorld] Waiting for HOME ('android.process.acore') to be launched...
[2014-07-09 13:35:07 - HelloWorld] ------------------------------
[2014-07-09 13:35:07 - HelloWorld] Android Launch!
[2014-07-09 13:35:07 - HelloWorld] adb is running normally.
[2014-07-09 13:35:07 - HelloWorld] Performing com.johndavisdesign.helloworld.MainActivity activity launch
[2014-07-09 13:35:07 - HelloWorld] Automatic Target Mode: Preferred AVD 'Test' is available on emulator 'emulator-5554'
[2014-07-09 13:35:07 - HelloWorld] Uploading HelloWorld.apk onto device 'emulator-5554'
[2014-07-09 13:35:08 - HelloWorld] Installing HelloWorld.apk...
[2014-07-09 13:35:08 - HelloWorld] Success!
[2014-07-09 13:35:08 - HelloWorld] Starting activity com.johndavisdesign.helloworld.MainActivity on device emulator-5554
[2014-07-09 13:35:08 - HelloWorld] ActivityManager: WARNING: linker: libdvm.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[2014-07-09 13:35:08 - HelloWorld] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.johndavisdesign.helloworld/.MainActivity }
[2014-07-09 13:35:21 - HelloWorld] HOME is up on device 'emulator-5554'
[2014-07-09 13:35:21 - HelloWorld] Application already deployed. No need to reinstall.
[2014-07-09 13:35:21 - HelloWorld] Starting activity com.johndavisdesign.helloworld.MainActivity on device emulator-5554
[2014-07-09 13:35:21 - HelloWorld] ActivityManager: WARNING: linker: libdvm.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[2014-07-09 13:35:21 - HelloWorld] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.johndavisdesign.helloworld/.MainActivity }
我的 logcat 文件内容如下:
07-09 17:35:06.550: D/AndroidRuntime(1582): Shutting down VM
07-09 17:35:06.550: E/AndroidRuntime(1582): FATAL EXCEPTION: main
07-09 17:35:06.550: E/AndroidRuntime(1582): Process: com.johndavisdesign.helloworld, PID: 1582
07-09 17:35:06.550: E/AndroidRuntime(1582): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.johndavisdesign.helloworld/com.johndavisdesign.helloworld.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.os.Handler.dispatchMessage(Handler.java:102)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.os.Looper.loop(Looper.java:136)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.ActivityThread.main(ActivityThread.java:5026)
07-09 17:35:06.550: E/AndroidRuntime(1582): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 17:35:06.550: E/AndroidRuntime(1582): at java.lang.reflect.Method.invoke(Method.java:515)
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-09 17:35:06.550: E/AndroidRuntime(1582): at dalvik.system.NativeStart.main(Native Method)
07-09 17:35:06.550: E/AndroidRuntime(1582): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.Activity.setContentView(Activity.java:1930)
07-09 17:35:06.550: E/AndroidRuntime(1582): at com.johndavisdesign.helloworld.MainActivity.onCreate(MainActivity.java:14)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.Activity.performCreate(Activity.java:5242)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-09 17:35:06.550: E/AndroidRuntime(1582): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-09 17:35:06.550: E/AndroidRuntime(1582): ... 11 more
07-09 17:35:06.550: W/dalvikvm(1582): threadid=1: thread exiting with uncaught exception (group=0xacd27ce8)
07-09 17:40:06.574: I/Process(1582): Sending signal. PID: 1582 SIG: 9
07-09 17:40:06.614: D/AndroidRuntime(1637): Shutting down VM
07-09 17:40:06.614: E/AndroidRuntime(1637): FATAL EXCEPTION: main
07-09 17:40:06.614: E/AndroidRuntime(1637): Process: com.johndavisdesign.helloworld, PID: 1637
07-09 17:40:06.614: E/AndroidRuntime(1637): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.johndavisdesign.helloworld/com.johndavisdesign.helloworld.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.os.Handler.dispatchMessage(Handler.java:102)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.os.Looper.loop(Looper.java:136)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.ActivityThread.main(ActivityThread.java:5026)
07-09 17:40:06.614: E/AndroidRuntime(1637): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 17:40:06.614: E/AndroidRuntime(1637): at java.lang.reflect.Method.invoke(Method.java:515)
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-09 17:40:06.614: E/AndroidRuntime(1637): at dalvik.system.NativeStart.main(Native Method)
07-09 17:40:06.614: E/AndroidRuntime(1637): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.Activity.setContentView(Activity.java:1930)
07-09 17:40:06.614: E/AndroidRuntime(1637): at com.johndavisdesign.helloworld.MainActivity.onCreate(MainActivity.java:14)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.Activity.performCreate(Activity.java:5242)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-09 17:40:06.614: E/AndroidRuntime(1637): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-09 17:40:06.614: E/AndroidRuntime(1637): ... 11 more
07-09 17:40:06.614: W/dalvikvm(1637): threadid=1: thread exiting with uncaught exception (group=0xacd27ce8)
我做错了什么?
编辑:
这里是 MainActivity.java:
package com.johndavisdesign.helloworld;
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);
}
}
编辑 2:
<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.johndavisdesign.helloworld.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
【问题讨论】:
-
MainActivity.onCreate() 的第 14 行是什么?
-
我在原帖中添加了 MainActivity.java。
-
发布你的activity_main.xml
-
我刚刚发布了它。感谢您查看我的问题。
-
在新建项目向导中,您指定要使用 API20 Android 4.4 KitKat Wear 进行编译。创建一个新项目并使用普通的 API19 Android 4.4 KitKat 进行编译。它基本上认为你想创建一个 Android Wear 项目,我假设你没有。
标签: java android eclipse android-emulator installation