Monday, 2 September 2013

app crashes when using action bar, what's wrong?

app crashes when using action bar, what's wrong?

so i'm learning the basics of making an android app, and i'm trying out
the action bar now. it doesn't give any errors, but when i run the app on
my phone it crashes. so this is the action bar:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_settings"
android:title="@string/action_settings"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:icon="@drawable/ic_action_search"
android:showAsAction="always" />
and the main activity java:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
startActivity(new Intent(this, Hallo.class));
return true;
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
and this is the hallo.class
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/hallo" />
so this is what i have. what's wrong? thanks for your anwser. now i'm here
anyways, what does the "this," mean at the intent? thanks again.

No comments:

Post a Comment