Currently I'm working on an Android Project consisting of Toolbar instead of the regular ActionBar.
I have defined the Toolbar in a separate layout file named as tool_bar.xml, and then I include the ToolBar in every layout where I need it.
My Activity's Layout file is named as acceptor.xml.
My Question is that, whenever I include the tool_bar.xml in acceptor.xml and provide the included layout an id, it gives me a force close error, and it goes smooth when I remove that id attribute.
Please help!
All the needed resources like Logcat, xml files, Java files are posted below : 
tool_bar.xml   
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="4dp"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
acceptor.xml   
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Attribute android:id causes the force close-->
<include layout="@layout/tool_bar"
android:id="@+id/action_accept"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvAcceptorHeader2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Below is the List of Donors you need!"
android:textColor="#8A0707"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="@+id/sort_divider2"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="@+id/tvAcceptorHeader2"
android:background="#000000" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sort_divider2"
android:layout_marginBottom="10sp"
android:layout_marginTop="10dp"
android:cacheColorHint="#00000000"
android:dividerHeight="3dp"></ListView>
<RelativeLayout
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/sort_divider2"
android:layout_margin="10sp">
<TextView
android:id="@+id/tvListEmpty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Filters Applied. Please apply the filters below!"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:content="@+id/content"
android:handle="@+id/handle"
android:orientation="horizontal">
<Button
android:id="@+id/handle"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/handle_sliding_closed" />
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10sp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvAcceptorHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:text="Please apply the filters below to show a list of Donors!"
android:textColor="#8A0707"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="@+id/header_divider"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_below="@+id/tvAcceptorHeader"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="1dp"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header_divider"
android:layout_margin="15dp"
android:orientation="vertical">
<Spinner
android:id="@+id/spinBGSort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:entries="@array/bg_types_sort"
android:prompt="@string/bg_prompt"
android:spinnerMode="dialog" />
<AutoCompleteTextView
android:id="@+id/acCitySort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="Your City here"
android:singleLine="true"></AutoCompleteTextView>
<EditText
android:id="@+id/etZipcodeSort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="Your ZIP CODE here"
android:singleLine="true"></EditText>
<CheckBox
android:id="@+id/cbLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:enabled="true"
android:text="Use my Location" />
<Button
android:id="@+id/bFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginLeft="5dp"
android:background="@drawable/button_selector"
android:text="Filter" />
</LinearLayout>
<View
android:id="@+id/sort_divider"
android:layout_width="match_parent"
android:layout_height="2dip"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#000000" />
</RelativeLayout>
</SlidingDrawer>
</RelativeLayout>
LogCat   
01-04 21:04:26.348 22744-22744/com.developit.bloodgency E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.developit.bloodgency, PID: 22744
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.developit.bloodgency/com.developit.bloodgency.AcceptorActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.developit.bloodgency.AcceptorActivity.onCreate(AcceptorActivity.java:107)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
01-04 21:15:00.718 24442-24442/com.developit.bloodgency E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.developit.bloodgency, PID: 24442
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.developit.bloodgency/com.developit.bloodgency.AcceptorActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.developit.bloodgency.AcceptorActivity.onCreate(AcceptorActivity.java:107)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
I hope this is sufficient to get what my problem is. Thanks in advance!
No comments:
Post a Comment