Android的ListView的刷新期间空指针异常 [英] null pointer exception during android listview refresh
本文介绍了Android的ListView的刷新期间空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想下载完成后更新我的列表视图,但它给我空指针异常我的code是按下
i want to update my list view after downloading complete but it gives me Nullpointer Exception my code is as per under
try {
URL url = new URL(GlobalVariable.Getstr());
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
int lenghtOfFile = c.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
String PATH = Environment.getExternalStorageDirectory()
+ "/download/";
Log.v(LOG_TAG, "PATH: " + PATH);
File file = new File(PATH);
file.mkdirs();
// String fileName = "workTest.mp3";
String fileName = GlobalVariable.Getstrpath().toString();
File outputFile = new File(file, fileName);
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
// int len1 = 0;
long total = 0;
// while ((len1 = is.read(buffer)) != -1) {
// total += len1;
// publishProgress(""+(int)((total*100)/lenghtOfFile));
// fos.write(buffer, 0, len1);
//
while ((count = is.read(buffer)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
// ArrayAdapter aa=new ArrayAdapter(FindFilesByType.this, android.R.layout.test_list_item,Ringtones);
// aa.setNotifyOnChange(true);
// lv1.setAdapter(aa);
try{
((ArrayAdapter) lv1.getAdapter()).notifyDataSetChanged();
// adapter.notifyDataSetChanged();
}
catch (Exception e) {
Log.i(LOG_TAG, "Error: " + e.toString());
}
我收到
15 04-28:56:17.198:信息/应用程序(624):错误:显示java.lang.NullPointerException
什么是错的我在做什么?
what is wrong i am doing?
在此先感谢
推荐答案
在这行例外到来。
和使用 notifyDataSetChanged();在适配器方法而非lvl.getAdapter()。 notifyDataSetChanged();
and use notifyDataSetChanged(); method on adapter rather than lvl.getAdapter(). notifyDataSetChanged();
编辑: notifydatasetChange看到这
希望它可以帮助..
这篇关于Android的ListView的刷新期间空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文