1

Can't figure out what's going wrong with this app. Looked all over the internet, been trying to fix this for the past 3 days, been looking all over the internet. The last two lines of the console look like this:

[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

Here's the 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>

Here's more of the console:

{[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
}

Here's the 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

Manifest 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>
anti-
  • 29
  • 6

5 Answers5

1

Target your app for version 19, not 20 and run on 19 emulator, not 20

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

In Manifest file,Change

android:targetSdkVersion="20"

to

android:targetSdkVersion="19"

and also run your project on api level 19 emulator.

Do not use API Level of 20 and Platform 4.4W, as Android Virtual Device. With Level 19 and Platform 4.2.2 set on AVD everything runs as it should.

check here targetSdkVersion setting

Community
  • 1
  • 1
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
  • Changed it to 19, still getting the same error. "Unfortunately, HelloWorld has stopped" is what's showing up on the emulator. – anti- Jul 29 '14 at 08:26
  • @anti-black Clean your project and also remove existing app from emulator and try again. – Giru Bhai Jul 29 '14 at 08:27
  • Done. Still getting the same error. Last line in the console is "ActivityManager: Starting: Intent...". And "Unfortunately, HelloWorld has stopped" shows up on the emulator screen. – anti- Jul 29 '14 at 08:37
  • Are you using emulator with api level 19 or below? – Giru Bhai Jul 29 '14 at 08:38
  • No. The only thing I'm able to select when I create an emulator is Level 20 in the "Target" drop-down. – anti- Jul 29 '14 at 08:40
  • @anti-black Create new emulator with api 19 and try on that. – Giru Bhai Jul 29 '14 at 08:41
  • When I create a new emulator, I'm not able to choose anything but "Android 4.4W API Level 20" in the target drop-down menu. It's the only option regardless of which device I choose. – anti- Jul 29 '14 at 08:44
  • @anti-black Then open "Android SDK Manager" and download api for api level 19 also. – Giru Bhai Jul 29 '14 at 08:45
  • Well, I decided to close and re-open Eclipse and now all of the options that I should have had have magically appeared. – anti- Jul 29 '14 at 08:49
  • @anti-black is it running now? – Giru Bhai Jul 29 '14 at 09:18
  • Finally worked. Thanks. Thank God for this website. I would have just given up with Android programming otherwise. – anti- Jul 29 '14 at 18:38
0

You can't just say button_touch, in the onCreate type this:

Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener(){
})
JoppeD
  • 95
  • 1
  • 7
0

ActivityManager: Warning: Activity not started, its current task has been brought to the front

Application already deployed. No need to reinstall.

It happens usually when your app is in the foreground (currently running) and you pressed run command without any code changes.

Based on this link you should set your targetSdkVersion to 19 not 20.

Community
  • 1
  • 1
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
0

Use this. Made a little change in your code. Extend Activity instead of ActionBarActivity. 'Activity' is the superclass of all. No need to import : "android.support.v7.app.ActionBarActivity;".

Your MainActivity.java file:

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.");

}
}

And your activity_main.xml is perfect.

Carshtokky
  • 41
  • 8