困扰" Hello World" Android应用

时间:2014-07-29 07:13:54

标签: android

无法弄清楚这个应用程序出了什么问题。看着整个互联网,过去3天一直试图解决这个问题,一直在互联网上寻找。控制台的最后两行如下所示:

[2014-07-29 01:46:01 - HelloWorld] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.helloworld/.MainActivity }
[2014-07-29 01:46:01 - HelloWorld] ActivityManager: Warning: Activity not started, its current task has been brought to the front

这是Java:

package com.example.helloworld;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

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

    @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);
    }
    public void button_touch(View v)
    {
        TextView tv = (TextView) findViewById(R.id.textView1);
        tv.setText("Hello, world.");

    }
}

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: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.example.helloworld.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="143dp"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="67dp"
        android:onClick="button_touch"
        android:text="Say hi" />


</RelativeLayout>

以下是更多的控制台:

{[2014-07-29 01:45:50 - HelloWorld] ------------------------------
[2014-07-29 01:45:50 - HelloWorld] Android Launch!
[2014-07-29 01:45:50 - HelloWorld] adb is running normally.
[2014-07-29 01:45:50 - HelloWorld] Performing com.example.helloworld.MainActivity activity launch
[2014-07-29 01:45:50 - HelloWorld] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Level20'
[2014-07-29 01:45:52 - HelloWorld] ------------------------------
[2014-07-29 01:45:52 - HelloWorld] Android Launch!
[2014-07-29 01:45:52 - HelloWorld] adb is running normally.
[2014-07-29 01:45:52 - HelloWorld] Performing com.example.helloworld.MainActivity activity launch
[2014-07-29 01:45:53 - HelloWorld] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Level20'
[2014-07-29 01:45:54 - HelloWorld] Application already deployed. No need to reinstall.
[2014-07-29 01:45:54 - HelloWorld] Starting activity com.example.helloworld.MainActivity on device emulator-5554
[2014-07-29 01:45:56 - HelloWorld] ActivityManager: WARNING: linker: libdvm.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[2014-07-29 01:45:59 - HelloWorld] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.helloworld/.MainActivity }
[2014-07-29 01:45:59 - HelloWorld] Application already deployed. No need to reinstall.
[2014-07-29 01:45:59 - HelloWorld] Starting activity com.example.helloworld.MainActivity on device emulator-5554
[2014-07-29 01:45:59 - HelloWorld] ActivityManager: WARNING: linker: libdvm.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[2014-07-29 01:46:01 - HelloWorld] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.helloworld/.MainActivity }
[2014-07-29 01:46:01 - HelloWorld] ActivityManager: Warning: Activity not started, its current task has been brought to the front
}

这是logcat:

07-29 06:49:01.152: I/Process(1711): Sending signal. PID: 1711 SIG: 9
07-29 06:49:02.522: D/AndroidRuntime(1770): Shutting down VM
07-29 06:49:02.522: W/dalvikvm(1770): threadid=1: thread exiting with uncaught exception (group=0xb0d3bce8)
07-29 06:49:02.532: E/AndroidRuntime(1770): FATAL EXCEPTION: main
07-29 06:49:02.532: E/AndroidRuntime(1770): Process: com.example.helloworld, PID: 1770
07-29 06:49:02.532: E/AndroidRuntime(1770): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld/com.example.helloworld.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.os.Handler.dispatchMessage(Handler.java:102)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.os.Looper.loop(Looper.java:136)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.ActivityThread.main(ActivityThread.java:5026)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at java.lang.reflect.Method.invokeNative(Native Method)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at java.lang.reflect.Method.invoke(Method.java:515)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at dalvik.system.NativeStart.main(Native Method)
07-29 06:49:02.532: E/AndroidRuntime(1770): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.Activity.setContentView(Activity.java:1930)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at com.example.helloworld.MainActivity.onCreate(MainActivity.java:16)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.Activity.performCreate(Activity.java:5242)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-29 06:49:02.532: E/AndroidRuntime(1770):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-29 06:49:02.532: E/AndroidRuntime(1770):     ... 11 more

清单xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="android.support.v7.appcompat">
    <uses-sdk android:minSdkVersion="7"/>
    <application />
</manifest>

6 个答案:

答案 0 :(得分:1)

将您的应用定位到版本19,而不是20,并在19仿真器上运行,而不是20

答案 1 :(得分:0)

在清单文件中,更改

android:targetSdkVersion="20"

android:targetSdkVersion="19"

并在api 19级模拟器上运行你的项目。

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

点击targetSdkVersion setting

答案 2 :(得分:0)

你不能在onCreate中输入button_touch:

Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener(){
})

答案 3 :(得分:0)

  

ActivityManager:警告:活动未启动,其当前任务已被带到前面

     

已部署应用程序。无需重新安装。

通常在你的应用程序处于前台(当前正在运行)并且你按下run命令而没有任何代码更改时发生。

根据此link,您应将 targetSdkVersion 设置为19而不是20。

答案 4 :(得分:0)

使用它。对代码做了一些改动。扩展Activity而不是ActionBarActivity。 &#39;活动&#39; 是所有人的超类。 无需导入:&#34; android.support.v7.app.ActionBarActivity;&#34;。

您的 MainActivity.java 文件:

package com.example.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;


public class MainActivity extends Activity {

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

@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);
}
public void button_touch(View v)
{
    TextView tv = (TextView) findViewById(R.id.textView1);
    tv.setText("Hello, world.");

}
}

您的activity_main.xml非常完美。

答案 5 :(得分:0)

当我要开发我的第一个Android应用程序时,我也面临同样的问题,但是由于你的Hello world项目不会发生这个问题。 实际上它是由于目标Sdk版本默认最新发生的。

解决方案:您可以通过在清单文件中更改以下代码,将目标Sdk版本更改为sdk文件夹中的版本

android:targetSdkVersion="20"

android:targetSdkVersion="19"

然后在Android模拟器上的API Level 19上运行您的项目。

但我建议您使用SDKManager.exe将SDK和平台文件更新到最新版本,这将是Android App Development的长期解决方案。 如果您遇到有关HEllO World Project的任何问题,那么请查看本教程以获取详细的分步信息: Android App Development with Hello World Project

相关问题