i am about to making the android application but due to FATAL EXCEPTION: main java.lang.NULLPOINTEREXCEPTION the application aren't saving the data please help me here
here is my EditNoteActivity
package com.example.notepad.myapplication;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.List;
public class EditNoteActivity extends ActionBarActivity implements View.OnClickListener {
String A, B;
int id;
Boolean isUpdate = false;
Button Save, Delete;
private Toolbar toolbar;
EditText edit;
EditText edit1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_notes);
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
EditText edit = (EditText) this.findViewById(R.id.editText2);
EditText edit1 = (EditText) this.findViewById(R.id.editText);
A = edit.getText().toString();
B = edit1.getText().toString();
Note note = new Note();
note.setDescription(A);
note.setTitle(B);
Save = (Button) findViewById(R.id.button);
Save.setOnClickListener(this);
Delete = (Button) findViewById(R.id.button2);
Delete.setOnClickListener(this);
Bundle bundle = getIntent().getExtras();
if (bundle != null && bundle.containsKey("source")) {
if (bundle.getString("source").equalsIgnoreCase("editpress")) {
isUpdate = true;
id = bundle.getInt("noteId");
A = bundle.getString("noteTitle");
B = bundle.getString("noteDescription");
} else if (bundle.getString("source").equalsIgnoreCase("addPress")) {
isUpdate = false;
} else {
Toast.makeText(this, "invalid argument", Toast.LENGTH_SHORT).show();
super.onBackPressed();
}
}
}
public void Save() {
A = edit.getText().toString();
B = edit1.getText().toString();
if (!isvalid()) {
return;
}
Note note = new Note();
note.setTitle(A);
note.setDescription(B);
Databasehandler data = new Databasehandler(this);
if (!isUpdate) {
data.addnote(note);
Toast.makeText(this, "notes added sucessfully", Toast.LENGTH_LONG).show();
} else {
}
List<Note> list = data.getAllNotes();
MainActivity.adapt.clear();
MainActivity.adapt.addAll(list);
MainActivity.adapt.notifyDataSetChanged();
super.onBackPressed();
}
public void Delete() {
}
public boolean isvalid() {
if (A.isEmpty() && A != null && B.isEmpty() && B != null) {
Toast.makeText(this, "please enter tittle and description", Toast.LENGTH_SHORT).show();
return false;
} else if (A.isEmpty() && A != null) {
Toast.makeText(this, "please enter title", Toast.LENGTH_SHORT).show();
return false;
} else if (B.isEmpty() && B != null) {
Toast.makeText(this, "please enter description", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button:
Save();
break;
}
}
}
Here is my Logcat error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.notepad.myapplication, PID: 30744
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notepad.myapplication/com.example.notepad.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
at com.example.notepad.myapplication.BlankFragment.setup(BlankFragment.java:64)
at com.example.notepad.myapplication.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
please Help me here as i have tried every possible combination .i will be very much thankful to you all and thankz in andvance.
First of all use boolean instead of Boolean, and try checking if your getIntent() is not returning null intent, before receiving bundle from intent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With