Reputation: 11
I've downloaded the latest adt bundle from android site I've got Eclipse Juno and the latest ADT and I've imported the latest SDK and API into the eclipse.
Then I've opened and tried to run the sample in built app proved by eclipse itself, but never got an output.
Then I've decided to create a simple app on my own, I've created a small app tried to run, even then I couldn't get any output. Then I've gone through ur website and got some suggestions stating to use "empty layout" instead of a "blank layout". I've tried that one too but no luck. I've come across another suggestion stating that there was an issue with API level 21 so downgraded it to 19 and tried running but no luck.
Below is the code I've used, added "try-catch", just to see if I could catch a proper exception.
-------Mainactivity.java---------
package com.suresh.firstapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int c;
Button add, sub;
TextView disp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c = 0;
add = (Button) findViewById(R.id.bt_add);
sub = (Button) findViewById(R.id.bt_sub);
disp = (TextView) findViewById(R.id.textView1);
try{
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
c++;
disp.setText("Your total is: "+ c);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
c--;
disp.setText("Your total is: "+ c);
}
});
}
catch(Exception e){
System.out.println(e);
}
}
}
Tried using code found in this site, but no luck.
-------- activity_main.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"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="26dp"
android:layout_marginTop="38dp"
android:text="Add 1" />
<Button
android:id="@+id/button2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="22dp"
android:text="Subtract 1" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="24dp"
android:text="@string/stmt"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout> -->
<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" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Your total is 0"
android:textSize="40sp" />
<Button
android:id="@+id/bt_add"
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="add one" />
<Button
android:id="@+id/bt_sub"
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_alignLeft="@+id/bt_add"
android:layout_below="@+id/bt_add"
android:layout_marginTop="19dp"
android:text="sub one" />
</RelativeLayout>
and when I try to run, firstly my emulator doesn't even start most of the times I get some message stating "failed to open HAX device" or something like that, and when it works I get a message "Unfortunately, FirstApp has stopped" with the following error in logcat
--------Error-----------
08-04 11:13:04.839: D/AndroidRuntime(1769): Shutting down VM
08-04 11:13:04.839: W/dalvikvm(1769): threadid=1: thread exiting with uncaught exception (group=0xb0d71ce8)
08-04 11:13:04.859: E/AndroidRuntime(1769): FATAL EXCEPTION: main
08-04 11:13:04.859: E/AndroidRuntime(1769): Process: com.suresh.firstapp, PID: 1769
08-04 11:13:04.859: E/AndroidRuntime(1769): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.suresh.firstapp/com.suresh.firstapp.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.ActivityThread.access$800(ActivityThread.java:138)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.os.Handler.dispatchMessage(Handler.java:102)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.os.Looper.loop(Looper.java:136)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.ActivityThread.main(ActivityThread.java:5026)
08-04 11:13:04.859: E/AndroidRuntime(1769): at java.lang.reflect.Method.invokeNative(Native Method)
08-04 11:13:04.859: E/AndroidRuntime(1769): at java.lang.reflect.Method.invoke(Method.java:515)
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-04 11:13:04.859: E/AndroidRuntime(1769): at dalvik.system.NativeStart.main(Native Method)
08-04 11:13:04.859: E/AndroidRuntime(1769): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.Activity.setContentView(Activity.java:1930)
08-04 11:13:04.859: E/AndroidRuntime(1769): at com.suresh.firstapp.MainActivity.onCreate(MainActivity.java:19)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.Activity.performCreate(Activity.java:5242)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-04 11:13:04.859: E/AndroidRuntime(1769): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
08-04 11:13:04.859: E/AndroidRuntime(1769): ... 11 more
--------------androidmanifest.xml---------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.suresh.firstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Could someone please tell me where did I go wrong.
Thanks in advance
Regards, Suresh.
Upvotes: 1
Views: 130
Reputation: 563
try downgrading SDK tergetversion to
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
Upvotes: 0
Reputation: 1418
you're using 2 different root element in your activity_main.xml
but every xml document should have only one ROOT ELEMENT
delete second RelativeLayout:
<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" >
</RelativeLayout>
and add your all other xml tags into first <RelativeLayout />
tags and then try again
Upvotes: 0
Reputation: 411
Error in your activity_main.xml file
you entered or pasted two RelativeLayout root layout. All xml have only one root element.
Upvotes: 1