3

I have managed to fetch a string from the database and be able to store some of its elements in variable so as to reduce the number of times the app interacts with the databse. However I wanted the first element to be fetched from the database to be stored in a list but it keeps generating an error when i parse the string to a new list. please help

//String fetched from the database
final String[] rec = split(myresult,seperator);

//loc is the first String to be parsed to a String..
//desc is the 2nd string to be parsed to a textarea
//coords 3rd string which contains coordinates..
String  loc=rec[0];
final  String desc=rec[1];
String coords=rec[2];

//ERROR IS GENERATED HERE!!!
listmboya=new List(loc);
//Separate the coordinates in the string...
String seperator2=",";

String [] coordinates=split(coords,seperator2);

String lat=coordinates[0];
String lot=coordinates[1];

//convert them to floats..
item1=Float.parseFloat(lat);
item2=Float.parseFloat(lot);
4

3 回答 3

2

list is an iterface, try

   listmboya=new ArrayList();
   listmboya.add(loc);
于 2012-10-17T05:44:11.433 回答
0

List是抽象类,不能实例化。试试这样:

listmboya = new ArrayList<String>();
listmboya.add(loc);
于 2012-10-17T05:55:46.267 回答
0

您不能实例化List对象。它是一个interface而不是一个class。您需要一个ArrayList实现类,List并且没有构造函数ArrayList将 String 作为参数。

因此,您需要创建一个ArrayList<String>然后将您的字符串添加到它。

所以你需要这样做: -

List<String> listmboya=new ArrayList<String>();
listmboya.add(loc);

确保将您的身份声明listmboyaList<String>

更新: - 发布更多代码以防万一这不起作用。我们需要更多地研究它们。

于 2012-10-17T05:47:35.547 回答