![](/img/trans.png)
[英]Change text color that read from Strings.xml file doesn't work in custom Dialog on android Eclipse
[英]Read File from text file on Android doesn't work
更新::我做了一些更改,但是仍然有lines.get(0)的错误,这使我的应用再次崩溃了。
final List<String> lines = new ArrayList<String>();
String line;
int i = 0;
BufferedReader buffreader = null;
try {
buffreader = new BufferedReader(
new InputStreamReader(getAssets().open("test.txt")));
while((line = buffreader.readLine()) != null)
{
lines.add(line);
i++;
}
} catch (IOException e) {
}
这个
final String lines[]= {};
创建一个长度为0的数组,因此您无法访问任何元素。
使用List<String>
会是一个更好的主意,因为您不知道会读多少行。
List<String> lines = new ArrayList<String>();
// in the loop:
lines.add( line );
使用ArrayList<String> array = new ArrayList<String>();
这将根据需要为您分配内存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.