如何在Android类中初始化变量?

时间:2014-01-11 13:10:35

标签: java android

我初始化我的LOC或LAT变量时出现问题,应用程序崩溃,问题出在哪里?

public final class MyLocationListener  implements LocationListener {

Context c;
Camera mycam =Camera.open(1);
Float[] LOC;
Float[] LAT;


public MyLocationListener(Context context) {
     c= context;

     // read all file & spiting them

     String DataPoints = read_db("gpspoints");
     DataPoints.trim();
     String []ar=DataPoints.split("&");

     String[] twovar=ar[2].split("/");
     this.LOC[1]=(float) 1;
     this.LAT[1]=(float) 1;

     //end of read and Split
}

2 个答案:

答案 0 :(得分:1)

this.LAT = new Float[2];
this.LOC = new Float[2];

this.LOC[1]= (float) 1;
this.LAT[1]= (float) 1;

问题是你想在数组中设置一个值,但是你没有初始化数组。

答案 1 :(得分:0)

试试这个:

this.LOC[0]=(float) 1;
this.LAT[0]=(float) 1;