首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

Toast使用注意-解决异常:The application * has stopped unexpectedly.Please try again

2012-09-27 
Toast使用注意--解决错误:The application ** has stopped unexpectedly.Pleasetry again运行应用的时候出

Toast使用注意--解决错误:The application ** has stopped unexpectedly.Please try again

运行应用的时候出现了The application ** has stopped unexpectedly.Please ?try again 的错误,如下图:

Toast使用注意-解决异常:The application * has stopped unexpectedly.Please  try again

?

通过debug发现异常信息为:

?

Caused by: java.lang.RuntimeException: This Toast was not created with Toast.makeText()

?? ?at android.widget.Toast.setText(Toast.java:275)

?? ?at cn.and.ToastActivity.onCreate(ToastActivity.java:20)

?? ?at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

?? ?at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

?

分析andriod源码发现:

?

/** * 显示Toast * @param toastTxt 提示文本内容 */private void showToast(String toastTxt) {Toast t = new Toast(this);t.setDuration(Toast.LENGTH_SHORT);LinearLayout layout = new LinearLayout(this);TextView textView = new TextView(this);textView.setText(toastTxt);//textView.setTextSize(16);layout.addView(textView);t.setView(layout);t.show();}
1 楼 helwens 2012-05-25   好文章!真想转载

热点排行