无法解析构造函数ArrayAdapter(上下文、int、java.util.List)

无法解析构造函数ArrayAdapter(上下文、int、java.util.List),java,android,android-arrayadapter,Java,Android,Android Arrayadapter,所以我试图读入一个CSV文件,并在列表视图中显示它。我已经在原始目录中获得了csv文件,我已经成功地读取了每一行,并将其输出到日志中。下一步是获取该数据并将其显示在列表视图中。我的数据存储在ArrayList中,因此我尝试使用ArrayAdapater,但出现问题标题中的错误 maintactivity.java: private final List<Sample> coordArray = new ArrayList<>(); private void re

所以我试图读入一个
CSV
文件,并在
列表视图中显示它。我已经在原始目录中获得了csv文件,我已经成功地读取了每一行,并将其输出到日志中。下一步是获取该数据并将其显示在
列表视图中。我的数据存储在
ArrayList
中,因此我尝试使用
ArrayAdapater
,但出现问题标题中的错误

maintactivity.java:

    private final List<Sample> coordArray = new ArrayList<>();

private void readGPSData() {
    // Read the raw csv file
    InputStream is = getResources().openRawResource(R.raw.rawgps);
    // Reads text from character-input stream, buffering characters for efficient reading
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(is, Charset.forName("UTF-8"))
    );
    // Initialization
    String line = "";
    // Initialization
    try {
        // Step over headers
        reader.readLine();
        // If buffer is not empty
        while ((line = reader.readLine()) != null) {
            Log.d("MyActivity","Line: " + line);
            // use comma as separator columns of CSV
            String[] tokens = line.split(",");
            // Read the data
            Sample sample = new Sample();
            // Setters
            sample.setLat(tokens[0]);
            sample.setLon(tokens[1]);

            // Adding object to a class
            coordArray.add(sample);
            final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, coordArray);
            listView.setAdapter(adapter);
            // Log the object
            Log.d("My Activity", "Just created: " + sample);
        }

    } catch (IOException e) {
        // Logs error with priority level
        Log.wtf("MyActivity", "Error reading data file on line" + line, e);

        // Prints throwable details
        e.printStackTrace();
    }
}
private final List coordArray=new ArrayList();
私有void readGPSData(){
//读取原始csv文件
InputStream is=getResources().openRawResource(R.raw.rawgps);
//从字符输入流读取文本,缓冲字符以实现高效读取
BufferedReader reader=新的BufferedReader(
新的InputStreamReader(is,Charset.forName(“UTF-8”))
);
//初始化
字符串行=”;
//初始化
试一试{
//跨过标题
reader.readLine();
//如果缓冲区不是空的
而((line=reader.readLine())!=null){
Log.d(“我的活动”,“行:”+行);
//使用逗号作为CSV的分隔列
String[]tokens=line.split(“,”);
//读取数据
样本=新样本();
//二传手
sample.setLat(令牌[0]);
示例.setLon(令牌[1]);
//向类添加对象
添加(示例);
最终的ArrayAdapter=新的ArrayAdapter(getApplicationContext(),android.R.layout.simple\u list\u item\u 1,coordArray);
setAdapter(适配器);
//记录对象
Log.d(“我的活动”,“刚刚创建:”+示例);
}
}捕获(IOE异常){
//使用优先级记录错误
Log.wtf(“MyActivity”,“读取第行数据文件时出错”+第行,e);
//打印可丢弃的细节
e、 printStackTrace();
}
}

我已经多次使用
ArrayAdapter
,从未遇到过这个问题。感谢您的帮助

尝试使用
getActivity()
而不是
getApplicationContext(
)。

代码的问题在于:

private final List<Sample> coordArray = new ArrayList<>();

可能是因为
列表
?同样:我不认为这会导致问题或错误,如:无法解决constructor@nordine在回答问题之前,不妨考虑一下测试代码。只是我给你的50美分的建议。
List<Sample> coordArray = new ArrayList<Sample>();
ArrayAdapter<Sample> adapter = new ArrayAdapter<Sample>(getApplicationContext(), android.R.layout.simple_list_item_1, coordArray);