我正在制作一个解析在线 xml 提要的应用程序。我使用了片段和标签。
下面是代码
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.listview_file, container, false);
allPress_listView = (ListView) v.findViewById(R.id.listView_for_all);
progressBar=(ProgressBar)v.findViewById(R.id.progress_bar);
return v;
/* return inflater.inflate(R.layout.afragment, container, false);
listView=(ListView)fi*/
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
/* ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,Cheese );
listView.setAdapter(adapter);*/
progressBar.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try
{
//Thread.sleep(5000);
new DoSomeTask().execute();
}catch(Exception e){}
// myPd_ring.dismiss();
}
}).start();
}
问题是当我在具有 Android 版本 4.1.2 的三星 Galaxy Mini 上运行该应用程序时,它运行时不会崩溃,但是当我在较低版本上运行该应用程序时,它会崩溃。下面是错误。
E/AndroidRuntime(13631): FATAL EXCEPTION: Thread-164034
E/AndroidRuntime(13631): java.lang.ExceptionInInitializerError
E/AndroidRuntime(13631): at com.sl.sx.APR$1.run(AllReleases.java:74)
E/AndroidRuntime(13631): at java.lang.Thread.run(Thread.java:864)
E/AndroidRuntime(13631): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
E/AndroidRuntime(13631): at android.os.Handler.<init>(Handler.java:121)
E/AndroidRuntime(13631): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:607)
E/AndroidRuntime(13631): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:607)
E/AndroidRuntime(13631): at android.os.AsyncTask.<clinit>(AsyncTask.java:190)
E/AndroidRuntime(13631): ... 2 more