无法将 BufferedReader 应用到 Java Class 的构造函数中
Having trouble applying BufferedReader into Constructor of Java Class
我一直在开发一个 android 应用程序,它需要 GPS 坐标并使用二维数组来保存 [0][0] 和 [1024][512] 之间的坐标。截至目前,我已经 main_activity 创建了 BufferedReader,然后通过我创建的 CoordinatesHandler Class 传递它,它将过滤文本文件并拆分文本坐标并将它们作为整数存储在二维数组。尽管我无法通过构造函数传递 BufferedReader。感谢您的帮助。
这里是 CoordinatesHandler Class;
public class CoordinatesHandler{
Integer[][] CoordinatesValue = new Integer[1024][512];
public void CoordinatesHandler(BufferedReader reader){
String line;
while(true){
int y= 0;
try {
line = reader.readLine();
line.trim();
String splitCords[] = line.split("\s+");
if (!line.contains("#") && line != null) {
for (int x = 0; x <= 1024; x++) {
CoordinatesValue[x][y] = Integer.parseInt(splitCords[x]);
Log.d(Integer.toString(x),Integer.toString(y));
}
}else{break;}
}catch(IOException e){Log.d("error", "IO Exception");}
y++;
}
}
}
这是我在 main_activity、 注释中实现的部分(readIt 方法是提供给 android 开发人员下载和阅读文本的乘法方法之一网络文件):
public String readIt(InputStream stream, int len) throws IOException, UnsupportedEncodingException {
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
new CoordinatesHandler(reader);
return "hello";
}
问题是编译器不喜欢 "new CoordinatesHandler(reader)"
构造函数不应有 return 类型。从构造函数中删除 return 类型 "void" 并编译。
我一直在开发一个 android 应用程序,它需要 GPS 坐标并使用二维数组来保存 [0][0] 和 [1024][512] 之间的坐标。截至目前,我已经 main_activity 创建了 BufferedReader,然后通过我创建的 CoordinatesHandler Class 传递它,它将过滤文本文件并拆分文本坐标并将它们作为整数存储在二维数组。尽管我无法通过构造函数传递 BufferedReader。感谢您的帮助。
这里是 CoordinatesHandler Class;
public class CoordinatesHandler{
Integer[][] CoordinatesValue = new Integer[1024][512];
public void CoordinatesHandler(BufferedReader reader){
String line;
while(true){
int y= 0;
try {
line = reader.readLine();
line.trim();
String splitCords[] = line.split("\s+");
if (!line.contains("#") && line != null) {
for (int x = 0; x <= 1024; x++) {
CoordinatesValue[x][y] = Integer.parseInt(splitCords[x]);
Log.d(Integer.toString(x),Integer.toString(y));
}
}else{break;}
}catch(IOException e){Log.d("error", "IO Exception");}
y++;
}
}
}
这是我在 main_activity、 注释中实现的部分(readIt 方法是提供给 android 开发人员下载和阅读文本的乘法方法之一网络文件):
public String readIt(InputStream stream, int len) throws IOException, UnsupportedEncodingException {
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
new CoordinatesHandler(reader);
return "hello";
}
问题是编译器不喜欢 "new CoordinatesHandler(reader)"
构造函数不应有 return 类型。从构造函数中删除 return 类型 "void" 并编译。