Reputation: 1
I want to get a character of a string from a EditText and at the same time want to show the current location's latitude and longitude.
here shown a part of the code
Button btn=(Button)findViewById(R.id.format);
btn.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
showCurrentLocation();
}
});
protected void showCurrentLocation() {
text=name.getText().toString();
String finalText = "";
finalText = Character.toString(text.charAt(3));
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(GPSLocator.this, message,
Toast.LENGTH_LONG).show();
}
}
After compiling the code when i give any character and click on the sent button then a message is displayed on the screen like "The application GPSLocator(process com.vetexVervelnc GPSLocator) has stopped unexpectedly. Please try again Forse close "
Upvotes: 0
Views: 101
Reputation: 31963
Can you post the exact error you get?
The following code may be of assistance.
try{
finalText = Character.toString(text.charAt(3));
} catch {Exception e) {
finalText="";
}
Upvotes: 0
Reputation: 15477
try like this
finalText = ""+text.charAt(3);
Make sure you put correct permission in manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Upvotes: 2