2016-09-19 59 views
0

我一直在研究一个需要GPS坐标并使用2d数组来保存[0]和[1024] [512]之间坐标的android应用程序。截至目前,我有main_activity创建BufferedReader,然后通过我创建的CoordinatesHandler类传递它,它将通过文本文件进行过滤并拆分文本坐标并将它们作为整数存储在2d数组中。虽然我无法通过构造函数传递BufferedReader。谢谢您的帮助。无法将BufferedReader应用到Java类的构造函数中

这里是CoordinatesHandler类;

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"; 
    } 

的问题是,编译器不喜欢“新CoordinatesHandler(阅读器)”

回答

1

构造不应该有返回类型。从构造函数中移除返回类型“void”并进行编译。