Reputation: 29
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>
Upvotes: 1
Views: 894
Reputation: 86
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.
Upvotes: 0
Reputation: 10338
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.
Upvotes: 0
Reputation: 95
You can't just say button_touch, in the onCreate type this:
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener(){
})
Upvotes: 0
Reputation: 14398
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
Upvotes: 0
Reputation: 48252
Target your app for version 19, not 20 and run on 19 emulator, not 20
Upvotes: 1