I am using google Maps in my application. There is a
button on page on clicking first time the google Maps is loaded properly but again going
to that page and clicking that button crashes my
app.
This is my
code:
public class GoogleMaps
extends Activity {
MapFragment googleMapFragment =
null;
private static GoogleMap googleMap = null;
private String
provider;
MarkerOptions marker;
double latitude,
longitude;
private LocationManager locationManager;
ParseGeoPoint
myLatLng[];
int count_place, i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
//
TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemap_view);
try {
initilizeMap();
initParse();
} catch (Exception e) {
//
TODO: handle exception
Toast.makeText(getApplicationContext(),
e.toString(),
Toast.LENGTH_SHORT).show();
}
}
private void initParse() {
// TODO
Auto-generated method stub
Parse.initialize(this, "key","key");
ParseObject plcobj = new ParseObject("Details");
getLatLong();
ParseGeoPoint myGeoPiont = new ParseGeoPoint(latitude, longitude);
ParseGeoPoint userLocation = (ParseGeoPoint) plcobj.get("location");
final
ParseQuery query = ParseQuery.getQuery("Details");
query.whereNear("location", myGeoPiont);
query.setLimit(10);
query.whereWithinKilometers("location",
myGeoPiont, 10);
query.findInBackground(new FindCallback()
{
@Override
public void done(List objects,
ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
Iterator Itr = objects.iterator();
while
(Itr.hasNext()) {
ParseObject plcObjNext = (ParseObject)
Itr.next();
myLatLng[i] = plcObjNext.getParseGeoPoint("location");
i++; // Line 76
}
}
}
});
}
private void initilizeMap()
{
if (googleMap == null) {
googleMapFragment = ((MapFragment)
getFragmentManager()
.findFragmentById(R.id.map));
googleMap =
googleMapFragment.getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (googleMap ==
null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to
create maps", Toast.LENGTH_SHORT)
.show();
}
googleMap.setMyLocationEnabled(true);
Log.e("Maps",
"------EOC-------");
// Get the location manager
}
}
public void getLatLong() {
GPSTracker gps = new GPSTracker(GoogleMaps.this);
if (gps.canGetLocation())
{
longitude = gps.getLongitude();
latitude =
gps.getLatitude();
Toast.makeText(getApplicationContext(), longitude + " " +
latitude,
Toast.LENGTH_SHORT).show();
} // return boolean
true/false
else {
gps.showSettingsAlert();
}
}
}
This is my log:
10-18 13:37:24.219
E/AndroidRuntime(21624): FATAL EXCEPTION: main
10-18 13:37:24.219
E/AndroidRuntime(21624): java.lang.NullPointerException
10-18 13:37:24.219
E/AndroidRuntime(21624): at
com.example.restaurantfinder.GoogleMaps$1.done(GoogleMaps.java:76)
10-18
13:37:24.219 E/AndroidRuntime(21624): at
com.parse.FindCallback.internalDone(FindCallback.java:45)
10-18 13:37:24.219
E/AndroidRuntime(21624): at
com.parse.FindCallback.internalDone(FindCallback.java:1)
10-18 13:37:24.219
E/AndroidRuntime(21624): at com.parse.Parse$6$1.run(Parse.java:888)
10-18
13:37:24.219 E/AndroidRuntime(21624): at
android.os.Handler.handleCallback(Handler.java:605)
10-18 13:37:24.219
E/AndroidRuntime(21624): at
android.os.Handler.dispatchMessage(Handler.java:92)
10-18 13:37:24.219
E/AndroidRuntime(21624): at android.os.Looper.loop(Looper.java:137)
10-18
13:37:24.219 E/AndroidRuntime(21624): at
android.app.ActivityThread.main(ActivityThread.java:4517)
10-18 13:37:24.219
E/AndroidRuntime(21624): at java.lang.reflect.Method.invokeNative(Native
Method)
10-18 13:37:24.219 E/AndroidRuntime(21624): at
java.lang.reflect.Method.invoke(Method.java:511)
10-18 13:37:24.219
E/AndroidRuntime(21624): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
10-18
13:37:24.219 E/AndroidRuntime(21624): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
10-18
13:37:24.219 E/AndroidRuntime(21624): at dalvik.system.NativeStart.main(Native
Method)
No comments:
Post a Comment