I wrote some app that using lauot- procce bar and AsyncTask to do some work with xml and display it to user.
I want to dismess the proccess bar after back proccess will finish
but have some problem with my code
the errors:
FATAL EXCEPTION: AsyncTask #2
03-17 11:25:29.559: E/AndroidRuntime(31114): java.lang.RuntimeException: An error while executing doInBackground()
03-17 11:25:29.559: E/AndroidRuntime(31114): at android.os.AsyncTask$3.done(AsyncTask.java:200)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.lang.Thread.run(Thread.java:1019)
03-17 11:25:29.559: E/AndroidRuntime(31114): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
03-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
0 3-17 11:25:29.559: E/AndroidRuntime(31114): at java.util.ArrayList.get(ArrayList.java:311)
03-17 11:25:29.559: E/AndroidRuntime(31114): at com.example.News.NewsActivity$GetDataTask.doInBackground(NewsActivity.java:67)
03-17 11:25:29.559: E/AndroidRuntime(31114): at
my code is:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.progdailog);
mContext = this;
new GetDataTask().execute();
}
protected void onPostExecute(Integer result) {
listAdapter = new CustomListAdapter(mContext, R.layout.list_item,
ListNews);
ListView lv = ((ListActivity) mContext).getListView();
lv.setAdapter(listAdapter); // on test
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position != 0) {
// When clicked, show a toast with the TextView text
String s = ReadXML.hadashotListItems.get(position - 1).link;
Intent intent = new Intent(NewsActivity.this,
WebActivity.class);
intent.putExtra("url", s);
startActivity(intent);
}
}
public void onScrollStateChanged(final AbsListView view,
final int scrollState) {
if (scrollState == 0)
listAdapter.notifyDataSetChanged();
}
});
//progDailog.dismiss();
super.onPostExecute(result);
}
}
the line 67 is in code:
protected Integer doInBackground(Void... params) {
try {
ReadXML = new ReadXMLFile(mContext, getIntent().getExtras()
.getString("urlXml"));
ListNews.add("NEWS");
if (checkDate(ReadXML.hadashotListItems.get(0).pubDate,ReadXML.hadashotListItems.get(1).pubDate))
for (int i = 0; i < ReadXML.hadashotListItems.size(); i++) {
ListNews.add(ReadXML.hadashotListItems.get(i).title + "\n"
+ ReadXML.hadashotListItems.get(i).pubDate);
}
else
for (int i = ReadXML.hadashotListItems.size()-1; i >=0; i--) {
ListNews.add(ReadXML.hadashotListItems.get(i).title + "\n"
+ ReadXML.hadashotListItems.get(i).pubDate);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 1;
}
I think something wrong with view. hop you can help change the code that it will work.
There is an IndexOutOfBoundsException on line 67 of NewsActivity.java.
You are trying to access index 0 when there are no elements. I don’t think you have posted that code, so look for that line and fix the incorrect index access.