This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
i'm working on a project for indoor navigation and need to add a groundOverlay with the floorplan of the building. I've followed the guidelines on the Documentation from Google dev site. But its giving me NullPointerException when i try to add the overlay to the map.
Heres my code:
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setIndoorEnabled(true);
mMap.setOnIndoorStateChangeListener(this);
mMap.setPadding(0,0,50,0);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-28.666957, -55.994823), 19));
//add mapOverlay
LatLngBounds iffBounds = new LatLngBounds(
new LatLng(-28.667177,-55.995104),
new LatLng(-28.667061,-55.994443)
);
GroundOverlayOptions iffMap = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.raw.piso_1))
.positionFromBounds(iffBounds);
mapOverlay = mMap.addGroundOverlay(iffMap);
}
I have tried debbuging the code and i can't see anything wrong, everything is being correctly instantiated, but when it executes the last line
mapOverlay = mMap.addGroundOverlay(iffmap);
My app crashes.
Here's the StackTrace from logCat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.imerljak.vegvisir, PID: 2390
java.lang.NullPointerException: null reference
at maps.w.c.a(Unknown Source)
at maps.ad.g$a.<init>(Unknown Source)
at maps.ad.g.a(Unknown Source)
at maps.ad.w.<init>(Unknown Source)
at maps.ad.u.a(Unknown Source)
at vo.onTransact(:com.google.android.gms.DynamiteModulesB:182)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addGroundOverlay(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addGroundOverlay(Unknown Source)
at br.com.imerljak.vegvisir.MapsActivity.onMapReady(MapsActivity.java:62)
at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzt$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)
at xz.a(:com.google.android.gms.DynamiteModulesB:82)
at maps.ad.u$5.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
PS: if anyone has any tips that will help me developing this app (like a good API for indoor navigation) i will be grateful :)
Your mapOverlay instance refence seems not to be initialized correctly...
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 3 years ago.
I am trying to declare a RecyclerView in an activity in my project. When I switch to this activity, the project crashes.
I am getting a NullPointerException when I try to instantiate my RecyclerView, see error below:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.marykate.marykatefordefyp, PID: 13490
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.marykate.marykatefordefyp/com.example.marykate.marykatefordefyp.ViewFavourites}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2264)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.access$1100(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5336)
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:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.marykate.marykatefordefyp.ViewFavourites.onCreate(ViewFavourites.java:54)
at android.app.Activity.performCreate(Activity.java:5302)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228
I have looked at similar questions on this site but none have the answer I am looking for. I am not referencing the wrong xml file and I am calling the correct RecyclerView.
See my code below:
RecyclerView eventsListview;
List<Favourite> favourites = new ArrayList<>();
FaveAdapter adapter = new FaveAdapter(this, R.layout.eventlist_layout, favourites);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_favourites);
eventsListview.findViewById(R.id.eventsListview1); //the line causing an error
Does anyone know what might be causing this?
eventsListview = (RecyclerView)findViewById(R.id.eventsListview1);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm building an Android app that finds and displays locations of nearest pharmacies and their details in a custom info window. When I run the app it is able to launch but after clicking on the button that will display the nearest pharmacies but the app crashed so I checked the Logcat and found this error:
java.lang.IllegalArgumentException: GoogleApiClient is not configured to use LocationServices.API required for this call.
I don't know if its this part of the code that is creating this error
Button btnPharma = (Button) findViewById(R.id.btnPharma);
btnPharma.setOnClickListener(new View.OnClickListener(){
String search = "pharmacy";
#Override
public void onClick (View v){
mMap.clear();
String url = getUrl(latitude, longitude, search);
Object[] DataTransfer = new Object[2];
DataTransfer[0] = mMap;
DataTransfer[1] = url;
GetNearbyBanksData getNearbyPlacesData = new GetNearbyBanksData();
getNearbyPlacesData.execute(DataTransfer);
Toast.makeText(pharma2.this, "These are your Nearby Pharmacies! ",
Toast.LENGTH_LONG).show();
}
});
This is the button for the class that performs the displaying of the nearest pharmacies.
this is the Logcat error lines
java.lang.IllegalArgumentException: GoogleApiClient is not configured to use LocationServices.API required for this call.
at com.google.android.gms.common.internal.zzbp.zzb(Unknown Source)
at com.google.android.gms.common.api.internal.zzbd.zze(Unknown Source)
at com.google.android.gms.internal.zzbym.requestLocationUpdates(Unknown Source)
at com.example.sachiewerk.smart_healthcare.pharma2.onConnected(pharma2.java:304)
at com.google.android.gms.common.internal.zzad.zzk(Unknown Source)
at com.google.android.gms.common.api.internal.zzbd.zzj(Unknown Source)
at com.google.android.gms.common.api.internal.zzar.zzahc(Unknown Source)
at com.google.android.gms.common.api.internal.zzar.onConnected(Unknown Source)
at com.google.android.gms.common.api.internal.zzbl.onConnected(Unknown Source)
at com.google.android.gms.common.api.internal.zzw.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzab.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzn.zzajo(Unknown Source)
at com.google.android.gms.common.internal.zze.zzs(Unknown Source)
at com.google.android.gms.common.internal.zzi.zzajp(Unknown Source)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
You need to create two differents GoogleApiClient instances: one for LocationServices API and another for Places API.
I'm trying to retrieve the position of the device. unfortunately my code continues to generate exceptional but I can not figure out what creates the problem.
To take the position, I followed what was written in https://developer.android.com/training/location/retrieve-current.html#play-services
Could anyone give me some advice?
This is my code:
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
//some other methods...
And this is the error i get during the execution:
FATAL EXCEPTION: main
Process: com.filippocalabrese.whereismycar, PID: 12436
java.lang.NoSuchMethodError: No direct method
(Landroid/content/Context;Landroid/os/Looper;ILcom/google/android/gms/common/internal/zzg;Lcom/google/android/gms/common/api/GoogleApiClient$ConnectionCallbacks;Lcom/google/android/gms/common/api/GoogleApiClient$OnConnectionFailedListener;)V
in class Lcom/google/android/gms/common/internal/zzk; or its super
classes (declaration of 'com.google.android.gms.common.internal.zzk'
appears in
/data/app/com.filippocalabrese.whereismycar-1/split_lib_dependencies_apk.apk:classes15.dex)
at com.google.android.gms.location.internal.zzb.(Unknown Source)
at com.google.android.gms.location.internal.zzl.(Unknown Source)
at com.google.android.gms.location.LocationServices$1.zzn(Unknown
Source)
at com.google.android.gms.location.LocationServices$1.zza(Unknown
Source)
at
com.google.android.gms.common.api.GoogleApiClient$Builder.zza(Unknown
Source)
at
com.google.android.gms.common.api.GoogleApiClient$Builder.zzvq(Unknown
Source)
at
com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown
Source)
at
com.filippocalabrese.whereismycar.MainActivity.onCreate(MainActivity.java:34)
at android.app.Activity.performCreate(Activity.java:6662)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
I've tryed to Google it and search for a solution but i've had no luck at all :/
java.lang.NoSuchMethodError
I suspect the android version you are using is different from the tutorial you are following on. sometimes method signatures get updated along the versions. Please verify that you have the right version as the tutorial/article you are trying to use.
I'm trying to retrieve the location of the device calling the method connect of the class LocationClient in my activity, however when the call is made the system crashes with the following exception:
**FATAL EXCEPTION: main
Process: com.unipagossales, PID: 3833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.unipagossales/com.unipagossales.app.merchants.MerchantFragmentActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.location.internal.GoogleLocationManagerService.START }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.location.internal.GoogleLocationManagerService.START }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1773)
at android.app.ContextImpl.bindService(ContextImpl.java:1751)
at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
at com.google.android.gms.internal.v.a(Unknown Source)
at com.google.android.gms.internal.u.connect(Unknown Source)
at com.google.android.gms.location.LocationClient.connect(Unknown Source)
at com.unipagossales.app.merchants.MerchantFragmentActivity.onStart(MerchantFragmentActivity.java:122)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
at android.app.Activity.performStart(Activity.java:5949)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
... 10 more
**
This is the way I create my LocationClient:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.merchant_activity);
...
// Create a new global location parameters object
locationRequest = LocationRequest.create();
locationRequest.setInterval(Constants.UPDATE_INTERVAL_MILLISECONDS);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setFastestInterval(Constants.FAST_INTERVAL_CEILING_MILLISECONDS);
// Initialize the location client
locationClient = new LocationClient(this, new LocationClientConnectionCallbacks(), new LocationClientOnConnectionFailedListener());
}
#Override
protected void onStart() {
super.onStart();
...
locationClient.connect();
...
}
Changing the target SDK version to "19" helped me.
This problem is related to the fact that Android VM is not being able in runtime to find the definition of the action act=com.google.android.location.internal.GoogleLocationManagerService.START in Google Play Services.
You will need to set your Google Play Services following the next blog:
http://mflerackers.wordpress.com/2014/09/09/noclassdeffounderror-for-googleplayservicesutil/
Then you will need to increment the VM values in eclipse.ini, follow this one:
Unable to execute dex: GC overhead limit exceeded in Eclipse
This should fix your exception collaterally.
I get this weird error in my MainActivity, can't reproduce it myself but this is what I get in Crash report:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65538, result=0, data=null} to activity {lv.mobi.android/lv.mobi.android.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3455)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3498)
at android.app.ActivityThread.access$1300(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
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:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at lv.mobi.android.b.aj.a(Unknown Source)
at android.support.v4.app.FragmentActivity.onActivityResult(Unknown Source)
at lv.mobi.android.MainActivity.onActivityResult(Unknown Source)
at android.app.Activity.dispatchActivityResult(Activity.java:5423)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3451)
... 11 more
I thought it could be something in onActivityResult, but can't figure out what, my result function doesn't have much in it:
#Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
if(_resultCode==Activity.RESULT_OK){
reloadUser();
}
}
According to my guess, you need to put below code
if(resultCode != RESULT_CANCELED){
if(_resultCode==Activity.RESULT_OK){
reloadUser();
}
}
Because you are cancelling that activity/process due to that intent is getting null value.
For what i can see and based on the comments. It's a NullPointerException, witch means some where in your code you are not initializing a variable / class or something is returning null. If you like to read up on it to get a better understanding here is a link NullPointerException Documentation, also it would help to post some of your code.