Android - Displaying Customized Toast in ListFragment throws an Error -
i didn't find post display customized toast in listfragment. have search around. here customized xml file used display toast.
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativelayout5" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cc000000" > <textview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/course_deleted" android:textappearance="?android:attr/textappearancelarge" android:textcolor="@android:color/white" > </textview> <imageview android:id="@+id/imageview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/textview1" android:layout_margin="5dip" android:contentdescription="@string/delete" android:src="@drawable/ic_action_discard" > </imageview> <textview android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/imageview1" android:gravity="center" android:textcolor="@android:color/white" > </textview> </relativelayout>
and method inflate xml is:
private void delete(string course) { databasehandler db = new databasehandler(this.getactivity()); boolean status = db.deletecourse(uni, course); if (status) { view = inflater.inflate( r.layout.custom_toast_layout_course_deleted, (viewgroup) getactivity() .findviewbyid(r.id.relativelayout5)); toast toast = new toast(getactivity()); toast.setgravity(gravity.top, 0, 0); toast.setduration(toast.length_short); toast.setview(view); toast.show(); } }
but when app runs show error:
11-13 09:48:13.521: e/androidruntime(11052): fatal exception: main 11-13 09:48:13.521: e/androidruntime(11052): java.lang.nullpointerexception 11-13 09:48:13.521: e/androidruntime(11052): @ ......delete(pokfragment.java:173) 11-13 09:48:13.521: e/androidruntime(11052): @ ......access$0(pokfragment.java:161) 11-13 09:48:13.521: e/androidruntime(11052): @ ......onclick(pokfragment.java:107)
and line 173 is:
view = inflater.inflate(r.layout.custom_toast_layout_course_deleted,(viewgroup) getactivityity().findviewbyid(r.id.relativelayout5));
what wrong in code? works fine activity goes wrong listfragment.
need change
view = inflater.inflate( r.layout.custom_toast_layout_course_deleted, null));
also check inflater
must not null.
android android-activity android-fragments nullpointerexception android-toast
No comments:
Post a Comment