Reputation: 213
Issue: ProjectManager.getInstance();
gives null object, I am clueless I have done the code as below,
Activity class & Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="proj.Mobi">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:hardwareAccelerated="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.here.android.maps.appid" android:value="WcIOjXKhgYk8" />
<meta-data android:name="com.here.android.maps.apptoken" android:value="XaRs1SILAVi2sw" />
<meta-data android:name="com.here.android.maps.license.key" android:value="phEpi5ZL3jiNTElgM3ldzrJTeevoNeYY47oE9eSzgJfySv=" />
</application>
</manifest>
I am creating class of map activity below, I have created the PositioningManager.getInstance()
it gives null object by Toast popup
public class MainActivity extends AppCompatActivity {
// map embedded in the map fragment
private Map map = null;
// map fragment embedded in this activity
private MapFragment mapFragment = null;
private PositioningManager positioningManager = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Positioning Manager
positioningManager = PositioningManager.getInstance();
if (positioningManager == null) {
Toast.makeText(MainActivity.this, " Positioning Null", Toast.LENGTH_LONG).show();
}
// Search for the map fragment to finish setup by calling init().
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(
OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap();
// Set the map center to the Vancouver region (no animation)
map.setCenter(new GeoCoordinate(12.9172, 77.5738, 0.0),
Map.Animation.NONE);
// Set the zoom level to the average between min and max
map.setZoomLevel(
(map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
Toast.makeText(MainActivity.this, "Error:" + error.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
}
Upvotes: 0
Views: 288
Reputation: 2190
Everything that's HERE Maps related needs to happen after initialization. This is applicable for everything related to the HERE MobileSDK.
Try getting the PositioningManager inside your EngineInitListener.onEngineInitializationCompleted (and keep in mind, once you get the instance, you also have to call start on it to receive any events)
Upvotes: 1