-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullPointerException when running on Android #3
Comments
Hey @tjvantoll can you try a real device as well? Just tested on my 4.4.4 device with your code without a problem. Will try an emulator now. |
Hmmmm... might be on my end. Yeah hold on. Uploading now. |
Here it is: https://github.com/tjvantoll/HotOrCold |
Ka-boom! Same error here. I'm guessing it's a timing issue. I instantiate it from a button, you do it when the app loads. |
Race conditions ftw! I’m guessing this might be because I’m using Angular 2, so the app itself may not be “ready” in the constructor of the first Component. @hdeshev might have some ideas. |
Yes, I was wondering where the xml file was and saw Angular :) Haven't used that before so it's a bit hard to say really. It's not a race condition I think as wrapping the I'll check the Mapbox github repo as well |
Ah, found sth, hang on |
Looks like with Angular the context (the activity really) is not initialized when the mapbox module is loaded. Since the plugin was caching that at the top (near the imports) the value wasn't re-evaulated when the Grab 1.1.1 from npm while it's hot (or cold)! |
Oh btw I never tested this change without that timeout around |
🎉I’ll give it a shot tomorrow to confirm it works. Thanks for jumping on this so quickly! |
Unfortunately this doesn’t seem to work without the I also tried switching the logic to be driven off of a <StackLayout [loaded]="loadMap()">
<!-- stuff -->
</StackLayout> That approach seems to actually make more sense than the Component’s |
This kind of use is not something the Mapbox guys anticipated. Perhaps it's a good idea to log this with them as I don't see how this plugin could fix an issue that's really a Mapbox-NativeScript(with Angular) issue. |
Btw, that |
Yeah agreed. I’d like to see what @hdeshev or one of the people on our Angular team thinks about this and I can take it from there. |
Has there been any update on this? I'm running into this same issue? Where did you place the setTimeout code @tjvantoll ?? thanks |
@MikeHuntington To my knowledge there are no updates, but the import {Component} from "angular2/core";
var mapbox = require("nativescript-mapbox");
@Component({
selector: "my-app",
template: `
<StackLayout [loaded]="layoutLoaded()">
...
</StackLayout>
`
})
export class AppComponent {
layoutLoaded() {
setTimeout(showMap, 1000);
}
showMap() {
mapbox.show({
accessToken: "...",
style: mapbox.MapStyle.EMERALD,
showUserLocation: false
});
}
} You can show an activity indicator or something in the time it takes to load the map if the delay is awkward. |
I'm getting a different error when creating the map on android:
I also use angular for my project. I've tried on multiple emulated android version and an actual device. I get the same error in all cases. |
Solved the issue. Ultimately, I just had to set an initial position when showing the map on Android. |
+1 Get the same on vanilla. The loaded event fires to early on Android 2.3. Works when defined in XML. Using setTimeout(showmap, 50) solution from @tjvantoll solves the problem until a fix is released. (Using 50 ms instead of 1000ms). By the way: Thanks for a great plugin :-) |
@Stavanger75 about to push an update that handles this delay automatically. |
@EddyVerbruggen Can confirm it is working on Android. Thanks :-) |
Hey @EddyVerbruggen,
Just tried out the plugin and it works great on iOS, but I’m getting the following error on Android:
Any idea what’s up? I’m testing on an Android 5.x emulator and I have
showUserLocation
turned off. Here’s the code I’m using:Thanks.
The text was updated successfully, but these errors were encountered: