I have a floating button in a fragment and wants to pass intent to another activity. However, when I press the floating button, it leads to "Unable to start activity ComponentInfo" error.
Below is the logcat:
01-29 15:51:07.361 5909-5909/com.example.l33902.contactmanagment1512 E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.l33902.contactmanagment1512/com.example.l33902.contactmanagment.CreateContactListActivity}: java.lang.NullPointerException: println needs a message at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3155) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3263) at android.app.ActivityThread.access$1000(ActivityThread.java:197) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6897) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) Caused by: java.lang.NullPointerException: println needs a message at android.util.Log.println_native(Native Method) at android.util.Log.d(Log.java:164) at com.example.l33902.contactmanagment.CreateContactListActivity.onCreate(CreateContactListActivity.java:45) at android.app.Activity.performCreate(Activity.java:6550) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3108) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3263) at android.app.ActivityThread.access$1000(ActivityThread.java:197) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6897) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
This is my xml codes:
<?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"
android:id="@+id/plannerLinearLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/lvContactsCategories"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAddConList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
app:borderWidth="0dp"
android:clickable="true"
android:src="@drawable/ic_add_white" />
</LinearLayout>
</RelativeLayout>
-----------------EDIT-------------------
Below are my codes for the intent:
FloatingActionButton fab;
fab = (FloatingActionButton) rootView.findViewById(R.id.fabAddConList);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent createContactList = new Intent(context, CreateContactListActivity.class);
createContactList.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(createContactList);
}
});
Log.d(ex.getMessage())
? As ex.getMessage() might give you NPE. – Jiyeh