GPS Provider unknown error in Set Mock Location? - java

I'm trying to set my mock location however, I am getting the following error(Provider 'gps' unknown) and not to sure what is wrong?
I've got all the permission declared in my manifest.xml along with all the parameters.
Mock Location Method
//Initiates the method to set the phones location
private void setMockLocation() {
mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
mLocationManager.addTestProvider
(
LocationManager.GPS_PROVIDER,
"requiresNetwork" == "",
"requiresSatellite" == "",
"requiresCell" == "",
"hasMonetaryCost" == "",
"supportsAltitude" == "",
"supportsSpeed" == "",
"supportsBearing" == "",
android.location.Criteria.POWER_LOW,
android.location.Criteria.ACCURACY_FINE
);
Location newLocation = new Location(LocationManager.GPS_PROVIDER);
newLocation.setLatitude (32.4276462);
newLocation.setLongitude(-23.5509257);
newLocation.setAccuracy(500);
mLocationManager.setTestProviderEnabled
(
LocationManager.GPS_PROVIDER,
true
);
mLocationManager.setTestProviderStatus
(
LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null,
System.currentTimeMillis()
);
mLocationManager.setTestProviderLocation
(
LocationManager.GPS_PROVIDER,
newLocation
);
}
Error message
5-09 16:28:45.577 9070-9070/com.example.ankhit.saveme E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Provider "gps" unknown
at android.os.Parcel.readException(Parcel.java:1429)
at android.os.Parcel.readException(Parcel.java:1379)
at android.location.ILocationManager$Stub$Proxy.removeTestProvider(ILocationManager.java:956)
at android.location.LocationManager.removeTestProvider(LocationManager.java:1194)
at com.example.ankhit.saveme.UserLocation.setMockLocation(UserLocation.java:215)
at com.example.ankhit.saveme.UserLocation.access$000(UserLocation.java:41)
at com.example.ankhit.saveme.UserLocation$4.onClick(UserLocation.java:173)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Any ideas?

Related

Runtime errors when method is invoked?

I'm having some issues when I am running my method. How can I get it working so my mock locations will work on my actual device. (Ps. I've included permissions).
This provides a null pointer exception and I am not to sure why?
Method:
private void setMockLocation() {
{
Context context = null;
LocationManager locationManager = (LocationManager)context.getSystemService( Context.LOCATION_SERVICE );
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_COARSE );
String provider = locationManager.getBestProvider( criteria, true );
if ( provider == null ) {
Log.e( TAG, "No location provider found!" );
return;
}
locationManager.getLastKnownLocation(provider);
Location newLocation = new Location(LocationManager.GPS_PROVIDER);
newLocation.setLatitude(55.9500);
newLocation.setLongitude(3.1833);
newLocation.setAccuracy(500);
mLocationManager.setTestProviderEnabled
(
LocationManager.GPS_PROVIDER,
true
);
mLocationManager.setTestProviderStatus
(
LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null,
System.currentTimeMillis()
);
mLocationManager.setTestProviderLocation
(
LocationManager.GPS_PROVIDER,
newLocation
);
}
}
Stack Trace:
05-10 18:50:46.218 14398-14398/com.example.ankhit.saveme E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at com.example.ankhit.saveme.UserLocation.setMockLocation(UserLocation.java:220)
at com.example.ankhit.saveme.UserLocation.access$000(UserLocation.java:42)
at com.example.ankhit.saveme.UserLocation$4.onClick(UserLocation.java:175)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
However, when I add the code below to Context context code shown above I get a 'GPS Provider Unknown' Error
LocationManager locationManager = (LocationManager)context.getSystemService( Context.LOCATION_SERVICE );
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_COARSE );
String provider = locationManager.getBestProvider( criteria, true );
if ( provider == null ) {
Log.e( TAG, "No location provider found!" );
return;
}
lastLocation = locationManager.getLastKnownLocation(provider);
StackTrace:
05-10 18:54:37.395 15159-15159/com.example.ankhit.saveme E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Provider "gps" unknown
at android.os.Parcel.readException(Parcel.java:1429)
at android.os.Parcel.readException(Parcel.java:1379)
at android.location.ILocationManager$Stub$Proxy.removeTestProvider(ILocationManager.java:956)
at android.location.LocationManager.removeTestProvider(LocationManager.java:1194)
at com.example.ankhit.saveme.UserLocation.setMockLocation(UserLocation.java:218)
at com.example.ankhit.saveme.UserLocation.access$000(UserLocation.java:42)
at com.example.ankhit.saveme.UserLocation$4.onClick(UserLocation.java:175)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Any Ideas?
The NullPointerException should come from
Context context = null;
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE );
because context is null and you invoke a method on it.

Android Form Validation - How do I prevent a null field from crashing my application on button press?

I have a form which lets the user add entries into a raffle. However if the user leaves one of these fields blank and presses the submit button the app crashes. I tried to get around this by creating an if statement - if any of the fields are null, do nothing. Else, run the intent. However this still does not fix my problem. Pressing the button still causes a crash.
Here is my code:
public void addEntrySubmitButtonClick(View view) {
Intent addEntryIntent = getIntent();
int currentRaffleID = addEntryIntent.getIntExtra("raffleIndexInList", 0);
Raffle currentRaffle = Raffle.raffleArrayList.get(currentRaffleID);
String newEntryForename = String.valueOf(addEntryForename.getText());
String newEntrySurname = String.valueOf(addEntrySurname.getText());
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
int newEntryTicketCount = Integer.parseInt(String.valueOf(addEntryTicketCount.getText()));
int newEntryRaffleId = currentRaffle.getId();
if ((newEntryForename.equals(null)) || (newEntrySurname.equals(null)) || (String.valueOf(addEntryTelephoneNo).equals(null)) || (String.valueOf(addEntryTicketCount).equals(null))){
Intent failIntent = new Intent();
} else {
Entry newEntry = new Entry(newEntryForename, newEntrySurname, newEntryTelephoneNo, newEntryTicketCount, newEntryRaffleId);
// Get the list of raffles
for(Raffle currentEntryRaffle : Raffle.raffleArrayList) {
if((currentEntryRaffle.getId() == newEntryRaffleId) && ((currentEntryRaffle.getEntryArrayList().size()) < (currentEntryRaffle.getMaxTickets()))) {
int counter=0;
do {
currentEntryRaffle.getEntryArrayList().add(newEntry);
counter++;
} while(counter < newEntryTicketCount);
}
}
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
Here is the logcat:
10-24 10:48:42.599 19481-19481/com.example.rafflemanager E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3628)
at android.view.View.performClick(View.java:4128)
at android.view.View$PerformClick.run(View.java:17142)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3623)
            at android.view.View.performClick(View.java:4128)
            at android.view.View$PerformClick.run(View.java:17142)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:359)
at java.lang.Integer.parseInt(Integer.java:332)
at com.example.rafflemanager.AddEntry.addEntrySubmitButtonClick(AddEntry.java:48)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at android.view.View$1.onClick(View.java:3623)
            at android.view.View.performClick(View.java:4128)
            at android.view.View$PerformClick.run(View.java:17142)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:4787)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
            at dalvik.system.NativeStart.main(Native Method)
newEntryForename.equals(null)
The above expression will either evaluate to false or throw a NullPointerException. It is impossible to call a method on a null reference.
String.valueOf(addEntryTelephoneNo).equals(null)
The above expression will always evaluate to false. From String.valueOf javadoc:
Returns: if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned.
What you want instead is simply
addEntryTelephoneNo == null
and similar for other cases.
Furthermore note that you are trying to parse the value before you have null-checked it:
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
Move that code to after the null check.
I'm writing this from a smartphone so I won't include any codesamples with this answer.
Anyway... First of all remove all String.valueOf() calls - they are redundant. Second, to see if a value is null, check for value == null, not value.equals(null). If value is null, it doesn't have the method equals(), and will thus lead to a NullReferenceException.
Also, don't call Integer.parseInt(value) before you have made sure that value isn't null.
Disabling the send button when the EditText is empty when using imeOption= actionSend
message.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
public void afterTextChanged(Editable s) {
if (s == null || s.length() == 0) {
send.setEnabled(false);
message.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
}
else {
send.setEnabled(true);
message.setImeOptions( /* whatever you previously had */ );
}
}
To check if a string is empty (null or length 0) use TextUtils.isEmpty(). Here's an example:
int newEntryTelephoneNo;
if (TextUtils.isEmpty(addEntryTelephoneNo.getText())) {
newEntryTelephoneNo = 0;
} else {
newEntryTelephoneNo = Integer.parseInt(addEntryTelephoneNo.getText());
}
The problem in your logcat is this :
Caused by: java.lang.NumberFormatException: Invalid int: ""
Without line numbers, I deduct that the problem comes from one line like this one :
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
Reading the following docs give us a hint : http://developer.android.com/reference/java/lang/Integer.html#parseInt(java.lang.String)
Throws
NumberFormatException if string cannot be parsed as an integer value.
The Integer.parseInt() seems not able to parse an empty String to an int (and it's normal, because a int can't be null).
So I think you should make something like that :
int newEntryTelephoneNo = 0;
if (!TextUtils.isEmpty(addEntryTelephoneNo.getText())) {
newEntryTelephoneNo = Integer.parseInt(addEntryTelephoneNo.getText());
}
Not about the main question
Also, as other answers and comment said, you have to use this to check the "nullity" of an object :
myObject == null
instead of
myObject.equals(null)
because you can't even call equals() or any other methods on a null instance.
The logcat clearly shows the exception occurs when the call to Integer.parseInt throws a NumberFormatException. This occurs when the string cannot be converted to an int. If you check the line numbers you will see exactly which conversion generated the exception.
Depending on your needs you probably want to both test for acceptable invalid entries like empty string and catch NumberFormatException due to invalid input so that you can inform the user of the invalid entry.
Here is the code you need:
public void addEntrySubmitButtonClick(View view) {
Intent addEntryIntent = getIntent();
int currentRaffleID = addEntryIntent.getIntExtra("raffleIndexInList", 0);
Raffle currentRaffle = Raffle.raffleArrayList.get(currentRaffleID);
String newEntryForename = String.valueOf(addEntryForename.getText());
String newEntrySurname = String.valueOf(addEntrySurname.getText());
int newEntryTelephoneNo = Integer.parseInt(String.valueOf(addEntryTelephoneNo.getText()));
int newEntryTicketCount = Integer.parseInt(String.valueOf(addEntryTicketCount.getText()));
int newEntryRaffleId = currentRaffle.getId();
if (newEntryForename==null || newEntrySurname == null || String.valueOf(addEntryTelephoneNo) == null || String.valueOf(addEntryTicketCount) == null){
Intent failIntent = new Intent();
} else {
Entry newEntry = new Entry(newEntryForename, newEntrySurname, newEntryTelephoneNo, newEntryTicketCount, newEntryRaffleId);
// Get the list of raffles
for(Raffle currentEntryRaffle : Raffle.raffleArrayList) {
if((currentEntryRaffle.getId() == newEntryRaffleId) && ((currentEntryRaffle.getEntryArrayList().size()) < (currentEntryRaffle.getMaxTickets()))) {
int counter=0;
do {
currentEntryRaffle.getEntryArrayList().add(newEntry);
counter++;
} while(counter < newEntryTicketCount);
}
}
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
}
You have to replace .equals(null) with == null since calling a method on a null pointer will crash your app.

New error java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

I have a problem with sample code from google maps !
This code worked when i used eclipse. I changed for android studio and i have a wird error.
Error is : ( i have no onSaveInstanceState method)
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1360)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1378)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
at android.support.v4.app.DialogFragment.show(DialogFragment.java:138)
at com.example.smartoo.HomeActivity.servicesConnected(HomeActivity.java:325)
at com.example.smartoo.HomeActivity.stopUpdates(HomeActivity.java:373)
at com.example.smartoo.HomeActivity.onStop(HomeActivity.java:209)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1212)
at android.app.Activity.performStop(Activity.java:5376)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3185)
            at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3234)
            at android.app.ActivityThread.access$1100(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
Error is on this line :
errorFragment.show(getSupportFragmentManager(), LocationUtils.APPTAG);
The code :
/**
* Verify that Google Play services is available before making a request.
*
* #return true if Google Play services is available, otherwise false
*/
private boolean servicesConnected() {
// Check that Google Play services is available
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Log.d(LocationUtils.APPTAG, getString(R.string.play_services_available));
// Continue
return true;
// Google Play services was not available for some reason
} else {
// Display an error dialog
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 0);
if (dialog != null) {
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
errorFragment.setDialog(dialog);
errorFragment.show(getSupportFragmentManager(), LocationUtils.APPTAG);
}
return false;
}
}
Thx !
Normally, the above code is called inside onStart/OnResume method or after these methods, not inside onStop/onSaveInstance. You are trying to do some operation after activity is getting killed. Perform serivcesConnected call before onStop/finish/saveInstances method call.

Android takepicture failed at Android version 4.1.1 but succeed in version 4.0.0

I got the LogCat :
java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1061)
at android.hardware.Camera.takePicture(Camera.java:1006)
at com.cidtech.portraitcatch.service.MyService.takePic(MyService.java:168)
at com.cidtech.portraitcatch.service.MyService$1.onClick(MyService.java:78)
at android.view.View.performClick(View.java:4088)
at android.view.View$PerformClick.run(View.java:16984)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
the curial code is below:
public void takePic(){
home_takePic.setEnabled(false);
camera = Camera.open();
if(bitmapList == null){
bitmapList = new ArrayList<Bitmap>();
}
for(int i=0; i<5; i++){
camera.takePicture(null, null, new MyPictureCallback());
SystemClock.sleep(1000);
}
saveBitmapToSdcard();
releaseResource();
home_takePic.setEnabled(true);
}
I also do this:
public void takePic(){
home_takePic.setEnabled(false);
camera = Camera.open();
***camera.startPreview();***
if(bitmapList == null){
bitmapList = new ArrayList<Bitmap>();
}
for(int i=0; i<5; i++){
camera.takePicture(null, null, new MyPictureCallback());
SystemClock.sleep(1000);
}
// saveBitmapToSdcard();
releaseResource();
home_takePic.setEnabled(true);
}
but still get the same Exception
the method camera.takePicture have been performed in version 4.0.4 but faild in version 4.1.1, who can tell me how to solve it ,please help me ,thanks
You need to be making a call to startPreview() before you attempt the call to takePicture(). Do this after you call Camera.open().
As per Android documentation:
Important: Call startPreview() to start updating the preview surface.
Preview must be started before you can take a picture.
startPreview documentation

java.lang.NullPointerException:com.google.android.gms.maps.GoogleMap.moveCamera

I am currently working on the new Google Maps Android API v2.
My MapActivity class is working with my Samsung galaxy s3 ans s2 with the code below:
However, there are some particular devices are not working such as: GT-S5830i
class MapActivity extends FragmentActivity implements OnMapClickListener, OnMapLongClickListener, OnMarkerClickListener
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
tvLocInfo = (TextView)findViewById(R.id.locinfo);
android.support.v4.app.FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment myMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
ArrayList<Cooridnates> cooridnatesList = MainActivity.getList();
for(int i=0;i<cooridnatesList.size();i++)
{
//Toast.makeText(MapActivity.this, "SIZE : " + " " + cooridnatesList.size(), Toast.LENGTH_LONG).show();
LatLng point = new LatLng(cooridnatesList.get(i).getLat(),cooridnatesList.get(i).getLon());
tvLocInfo.setText("markers added");
myMap.addMarker(new MarkerOptions().position(point).title(point.toString()));
center=CameraUpdateFactory.newLatLng(point);
}
CameraUpdate zoom=CameraUpdateFactory.zoomTo(16);
myMap.moveCamera(center);
myMap.animateCamera(zoom);
myMap.setOnMapClickListener(this);
myMap.setOnMarkerClickListener(this);
markerClicked = false;
}
For some reason, I am getting this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coldice.plotfinder/com.coldice.plotfinder.MapActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source)
at com.coldice.plotfinder.MapActivity.onCreate(MapActivity.java:70)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
You function MainActivity.getList() probably returned an empty list, so for loop doesn't execute center=CameraUpdateFactory.newLatLng(point);.
it seems center is null in this >> myMap.moveCamera(center);, make an appropriate check on this variable before passing it in moveCamera method.
It seems problem is here. center might have null value, So to get proper explanation debug your application.
center is initialzed here.
center=CameraUpdateFactory.newLatLng(point);
It might assign null in center.
myMap.moveCamera(center); <<<PROBLEM is here
if(center != null )
myMap.moveCamera(center);

Categories

Resources