Irresponsive new Application after fixing automatically generated code



i'm quite new to Java and encountered some problems creating an Android Application with Eclipse Juno. I tried researching the errors already and was able to fix some - i was hoping someone could help me with the rest :)


So i create a new Android Application (Mininum SDK: API11, Target: API14 as an example), but the generated code is full of errors:



package com.example.test34;

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

public class MainActivity extends ActionBarActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}


Because of getting an error in the styles.xml file ,i started fixing by replacing that line in the (also in values-v11 and values-v14):


style name="AppBaseTheme" parent="android:Theme.Light"


instead of:


style name="AppBaseTheme" parent="Theme.AppCompat.Light" (adding the appcompat.jar didnt help)


Here the full code after fixing:



<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>


Also i removed android:showAsAction="never" in activity_main.xml.



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
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.test34.MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

</RelativeLayout>


The R.java (which was missing before) was automatically created after following those steps. After that i went to Properties > Java Build Path, added the appcompat.jar and checked the Android 4.0 checkbox.


All problems which previously occured are gone now.


Yet the App wont work on a Virtual Device (Galaxy Nexus API 14 or 19). Rightclicking on the project and selecting Run As.. > Android Application starts the Virtual Device, but i'm unable to even enter the Menu - it's not responding at all. When i start the Device first and follow the same steps (Run As.. > Android Application), it installs the app and gives the reply: "Unfortunately, The App has stopped.". Shouldnt it at least display "Hello world!"? Or did i destroy something by deleting the line android:showAsAction="never" from the activity_main.xml?


I'd be grateful for any kind of advice. Thanks a lot in advance :)


No comments:

Post a Comment