public void dialog(View view)
{
String msg="";
Toast toast=Toast.makeText(this, "", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout layout=(LinearLayout)toast.getView();
layout.setMinimumHeight(50);
ImageView image=new ImageView(getApplicationContext());
image.setImageResource(R.drawable.ic_launcher);
image.setMaxHeight(50);
image.setMaxWidth(50);
layout.addView(image, 0);
TextView txt=new TextView(getApplicationContext());
try
{
String url_1="http://192.168.43.1:8080/android/legendary.db",url_2="http://localhost:8080/android/legendary.db";
URI uri=new URI(url_2);
URL url=uri.toURL();
url.openConnection();
InputStream in=url.openStream();
toast.setText("---->");
txt.setText("\n-----****");
txt.setTextColor(Color.parseColor("#ffaaff"));
}
catch (Exception e)
{
msg = e.toString();
e.printStackTrace();
txt.setText(e.toString() + "\n-----****");
txt.setTextColor(Color.RED);
txt.setTextSize(16);
}
layout.addView(txt, 1);
toast.show();
latelog2(msg);
setlog2();
notice("錯誤---->", msg);
}
/*錯誤信息
android.os.NetworkOnMainThreadException
*/
錯誤信息是不能在主線程中進行網絡相關的操作。應該用thread+handler或者asynctask處理。