Open angel888808888 opened 6 years ago
Hi, this doesn't provide enough information. Please, show where are you calling Toasty.
By the way, are you using version 1.3.0
?
yes,I use 1.3.0,exception: public static void showToast(Context context,int type,String msg,boolean isWithIcon){ switch (type) { case 1: Toasty.info(context,msg, Toast.LENGTH_SHORT, isWithIcon).show(); break; case 2: Toasty.success(context,msg, Toast.LENGTH_SHORT, isWithIcon).show(); break; case 3: Toasty.warning(context,msg, Toast.LENGTH_SHORT, isWithIcon).show(); break; case 4: Toasty.error(context,msg, Toast.LENGTH_SHORT, isWithIcon).show(); break; } }
error : 05-17 09:40:42.975 15142-15142/com.creatoo.checkticket W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference at android.widget.ToastInjector.addAppName(ToastInjector.java:50) at android.widget.Toast.makeText(Toast.java:273) at es.dmoral.toasty.Toasty.custom(Toasty.java:171) at es.dmoral.toasty.Toasty.warning(Toasty.java:100) at com.force.librarybase.utils.ToastUtils.showToast(ToastUtils.java:69) at com.force.librarybase.network.net.common.DefaultObserver.onException(DefaultObserver.java:136) at com.force.librarybase.network.net.common.DefaultObserver.onError(DefaultObserver.java:73) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated(ObservableObserveOn.java:276) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:172) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252) at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109) at android.os.Handler.handleCallback(Handler.java:742)
I find that Toasy.custom having NullPointerException
Check if your msg
parameter is null.
it is not null
What device are you testing this on?
Redmi 4A
Are you call toasty from background thread? If yes, try this
private static void toast(final Context context, final String text, final int duration, final TOAST_TYPE type){
switch (type) {
case ERROR:
Toasty.error(context, text, duration, false).show();
break;
case SUCCESS:
Toasty.success(context, text, duration, false).show();
break;
case INFO:
Toasty.info(context, text, duration, false).show();
break;
case WARNING:
Toasty.warning(context, text, duration, false).show();
break;
case NORMAL:
Toasty.normal(context, text, duration).show();
break;
}
}
public static void showToast(final Context context, final String text, final int duration, final TOAST_TYPE type) {
if(Looper.myLooper() == Looper.getMainLooper()){
// call from foreground thread
toast(context, text, duration, type);
}
else {
// call from background thread
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
toast(context, text, duration, type);
}
});
}
}
用Toasty.info显示toast报NullPointerException
Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference at android.widget.ToastInjector.addAppName(ToastInjector.java:50) at android.widget.Toast.makeText(Toast.java:273) at es.dmoral.toasty.Toasty.custom(Toasty.java:171)