Android App stürzt ab wenn neue activity gestartet

job_2000

Mitglied
Hallo allerseits.
Ich bin sehr neu in der App-programmierung und wie schon in der Überschrift steht, ist mein Problem, dass die App abstützt, wenn ich die Activity "Eingabe" starte. Bevor ich den FloatingActionButton implementiert habe war alles wunderbar. Also muss der Fehler da liegen. In der Konsole wird mir eine java.lang.NullPointerException ausgegeben(
speichern.setOnClickListener(new View.OnClickListener() {
). Ich verseh aber nicht, warum da das eine Objekt null ist.

Ich hoffe das Problem ist klar geworden...
Danke schonmal für die Antworten!!!

Code:
package com.example.jonathan.notizbuch;

import android.content.Context;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class Eingabe extends AppCompatActivity {


    EditText mEdit;
    String[] notizenArray = new String[50];
    String FILENAME = "Notizen";

    @Override
    protected void onCreate(final Bundle notizenSpeichern) {
        super.onCreate(notizenSpeichern);
        setContentView(R.layout.activity_eingabe);


        mEdit = (EditText)findViewById(R.id.editText_Titel) ;


        FloatingActionButton speichern = (FloatingActionButton) findViewById(R.id.fab);
        speichern.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                for(int i = 0; i < notizenArray.length; i++) {
                    if(notizenArray[i] != null) {
                        notizenArray[i] = mEdit.getText().toString();
                        break;
                    }
                }
                notizenSpeichern.putStringArray("gespeicherteNotizen",notizenArray);
                try {
                    FileOutputStream speicher = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                    ObjectOutputStream oos = new ObjectOutputStream(speicher);
                    oos.writeObject(notizenArray);
                    oos.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();

                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });

    }

}
 
@Robat reichen die?
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.jonathan.notizbuch">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_eingabe"
    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.jonathan.notizbuch.Eingabe">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:id="@+id/editText_Titel"
            android:hint="Titel"
            android:textSize="30sp"
            android:inputType="text" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:inputType="text|textMultiLine"
            android:gravity="top"
            android:ems="10"
            android:id="@+id/editText_Notiz" />
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        app:fabSize="mini"
        app:srcCompat="@android:drawable/ic_menu_save"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginBottom="22dp"
        android:id="@+id/floatingActionButton2"
        app:backgroundTint="?attr/actionModeSplitBackground" />
</RelativeLayout>
 

Neue Themen


Zurück
Oben