0

I have a problem when I initialize my LOC or LAT variables, app crashes, where is the problem?

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
}
5
  • 1
    Strings are immutable. It should be DataPoints = DataPoints.trim(); Commented Jan 11, 2014 at 13:11
  • Don't let us guess what the error is. Post your logcat. Commented Jan 11, 2014 at 13:14
  • why don't people post the error message? Mind boggling. Commented Jan 11, 2014 at 13:15
  • curious why you aren't using index 0 for your LAT and LOC? Commented Jan 11, 2014 at 13:20
  • whats Exception on Log data? Commented Jan 11, 2014 at 13:32

2 Answers 2

1

Put

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

Before

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

The problem is you wanna set a value in an array, but you have not initialised the array.

Sign up to request clarification or add additional context in comments.

2 Comments

The problem is you wanna set a value in an array, but you have not initialised the array.
@user3185049 we have to use 2, because the array index starts at 0 and you want to set the value of the index 1.
0

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.