【发布时间】:2010-10-13 21:12:03
【问题描述】:
大家好, 我在奥地利,你好吗?
我已经开始开发 android 并编写自己的小应用程序,该应用程序从服务器获取文件以在 ListView 中显示信息。我真的花了一天的时间来研究从服务器获取文件的最佳和最简单的方法。但是我编写了程序并对其进行了测试——现在在运行虚拟 HTC 机器时出现了严重的错误消息。
调用:应用程序 org.me.newspuler(进程 org.me.newspuler)意外停止。请重试。
在此消息下方放置一个“强制关闭”按钮。
我真的不知道如何得到问题的提示,NewsPuler 是我的 APP,-我想我需要更多专家的帮助
我有 2 个类 - 一个用于下载文件(我认为这是错误的) - 一个用于主要活动 当编译器到达代码中创建“DownloadFile”实例的位置时...出现错误。
下载文件类:
package logik;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author raa
*/
public class DownloadFile {
InputStream is = null;
String link = null;
BufferedReader d = null;
URL url = null;
String s;
ArrayList<String> al = new ArrayList<String>();
public DownloadFile(String link) throws MalformedURLException{
this.link = link;
url = new URL(link);
try {
is = url.openStream();
} catch (IOException ex) {
Logger.getLogger(DownloadFile.class.getName()).log(Level.SEVERE, null, ex);
}
d = new BufferedReader(new InputStreamReader(is));
try {
while ((s = d.readLine()) != null) {
al.add(s);
}
} catch (IOException ex) {
Logger.getLogger(DownloadFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
public ArrayList getArrayList(){
return al;
}
}
在这里(如果您留下注释代码,它可以正常工作,但是当您取消注释时 - 不是)
包 org.me.newspuler;
import logik.DownloadFile;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author raa
*/
public class MainActivity extends Activity {
ArrayList<String> al;
DownloadFile df;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
ListView myListView = (ListView)findViewById(R.id.myListView);
// try {
// df = new DownloadFile("http://www.google.at/");
//
// } catch (MalformedURLException ex) {
// Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
// }
// al.add("Test");
// final ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
// android.R.layout.simple_list_item_1, al);
//
// myListView.setAdapter(aa);
}
}
我真的很高兴能得到一些帮助! 来自奥地利的问候。
【问题讨论】:
标签: android file download arraylist