Unfortunately ... has stopped

K

Kustaf

Neues Mitglied
0
Da ich meine Android App verbessern möchte, wollte ich ein NativeDrawer einfügen, um sie übersichtlicher zu machen. Ich habe jedoch das Problemm das beim Launcher die Meldung "Unfortunately (Appname) has stopped" kommt. Ich weis einfach nicht was genau nicht funktioniert. Hoffentlich kann mir jemand helfen. Ich benutze üpredings Eclipse, jedoch funktioniert es auch bei Android Studio nicht.

Meine Activity:

package com.example.navdrawer;

import android.app.ActionBar;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;

@SuppressWarnings("deprecation")
public class MainActivity extends Activity {

public DrawerLayout drawerlayout;
public ActionBarDrawerToggle drawertoggle;

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

drawerlayout = (DrawerLayout) findViewById(R.id.ganzesLayout);
drawertoggle = new ActionBarDrawerToggle(MainActivity.this, drawerlayout, R.drawable.ic_drawer, R.string.open, R.string.close);
drawerlayout.setDrawerListener(drawertoggle);


ActionBar dieactionbar = getActionBar();
dieactionbar.setHomeButtonEnabled(true);
dieactionbar.setDisplayHomeAsUpEnabled(true);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
drawertoggle.onConfigurationChanged(newConfig);
super.onConfigurationChanged(newConfig);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
drawertoggle.syncState();
super.onPostCreate(savedInstanceState);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@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.

if (drawertoggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}



Mein Layout:

<android.support.v4.widget.DrawerLayout
android:id="@+id/ganzesLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"

>

<RelativeLayout

android:id="@+id/HauptLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hauptlayout" />

</RelativeLayout>



<RelativeLayout
android:id="@+id/DrawerLayout"
android:layout_width="220dp"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_gravity="start"
>

<TextView
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drawer" />

</RelativeLayout>


</android.support.v4.widget.DrawerLayout>



Manifestdatei:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.navdrawer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="16"
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>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


LogCat:

03-13 14:32:32.599: D/AndroidRuntime(2344): Shutting down VM
03-13 14:32:32.599: E/AndroidRuntime(2344): FATAL EXCEPTION: main
03-13 14:32:32.599: E/AndroidRuntime(2344): Process: com.example.navdrawer, PID: 2344
03-13 14:32:32.599: E/AndroidRuntime(2344): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.navdrawer/com.example.navdrawer.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setHomeButtonEnabled(boolean)' on a null object reference
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.os.Handler.dispatchMessage(Handler.java:102)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.os.Looper.loop(Looper.java:135)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-13 14:32:32.599: E/AndroidRuntime(2344): at java.lang.reflect.Method.invoke(Native Method)
03-13 14:32:32.599: E/AndroidRuntime(2344): at java.lang.reflect.Method.invoke(Method.java:372)
03-13 14:32:32.599: E/AndroidRuntime(2344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-13 14:32:32.599: E/AndroidRuntime(2344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-13 14:32:32.599: E/AndroidRuntime(2344): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setHomeButtonEnabled(boolean)' on a null object reference
03-13 14:32:32.599: E/AndroidRuntime(2344): at com.example.navdrawer.MainActivity.onCreate(MainActivity.java:29)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.Activity.performCreate(Activity.java:5933)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
03-13 14:32:32.599: E/AndroidRuntime(2344): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
03-13 14:32:32.599: E/AndroidRuntime(2344): ... 10 more
03-13 14:32:38.407: I/Process(2344): Sending signal. PID: 2344 SIG: 9


 
hey du hast bei manchen emthoden die jeweilige super(...); methode nicht als erstes aufgerufen um für die standardimplementierung zu sorgen


und hast du dich da verschrieben oder schriebst dud as immer so?

fand es so witzig in dem Moment dass man sich so verschreiben kann XD

nciht böse gemeint
 
Zeile 29, das Objekt dieactionbar ist null.
 
Danke an für Antworten, hab das Problem gelöst.:biggrin::biggrin:
 
bitte posten für die nächasten
 
Hab zuerst das Problem so gelöst wie es sillage gesagt hat. Ich habe die Methoden der ActionBar gelöscht. Danach ging es dann ohne Probleme.
 

Ähnliche Themen

K
Antworten
1
Aufrufe
1.094
markus.tullius
markus.tullius
T
Antworten
8
Aufrufe
999
tzabbi
T
N
Antworten
6
Aufrufe
1.017
Nono
N
Zurück
Oben Unten