簡體   English   中英

如何在Android類中初始化變量?

[英]How can I initialize a variable in Android class?

初始化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
}

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

之前

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

問題是您想在數組中設置一個值,但尚未初始化數組。

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM