Google Maps API V2 android app on API level 8 up to 17 - google-maps-android-api-2

I am working with the Google maps API V2 and it is going fine. i have a 2.2.2 android device wich i use to debug my app.
now i just got a Galaxy Note 2, and when i try to debug on that device the app imidiatly crashed "project has stopped working".
So i just made a small example to test with. and again it runs great on 2.2.2 but not on 4.1.1.
this is the code i have for the small example exercise
Any suggestions would be much appreciated
My Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tv_location"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
My Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ss"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.ss.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.ss.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.ss.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key"/>
</application>
</manifest>
and my testing code
public class MainActivity extends FragmentActivity implements LocationListener{
private GoogleMap googleMap;
private LatLng source;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!=ConnectionResult.SUCCESS){
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else{
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(false);
LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locManager.getBestProvider(criteria, true);
Location loc = locManager.getLastKnownLocation(provider);
if(loc!=null){
onLocationChanged(loc);
}
source = new LatLng(loc.getLatitude(), loc.getLongitude());
//makeUrl = new MakeUrl(source, destination);
//String url = makeUrl.makeLocationUrl();
googleMap.moveCamera(CameraUpdateFactory.newLatLng(source));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
The stacktrace that i get on my NOTE 2
02-17 13:03:23.135: D/dalvikvm(9527): Late-enabling CheckJNI
02-17 13:03:23.170: E/Trace(9527): error opening trace file: No such file or directory (2)
02-17 13:03:23.345: D/dalvikvm(9527): GC_CONCURRENT freed 179K, 6% free 12453K/13191K, paused 2ms+1ms, total 33ms
02-17 13:03:23.345: D/dalvikvm(9527): WAIT_FOR_CONCURRENT_GC blocked 26ms
02-17 13:03:23.575: D/dalvikvm(9527): GC_CONCURRENT freed 279K, 7% free 12634K/13511K, paused 12ms+1ms, total 24ms
02-17 13:03:23.665: D/dalvikvm(9527): GC_CONCURRENT freed 276K, 7% free 12862K/13703K, paused 2ms+12ms, total 29ms
02-17 13:03:23.705: D/AbsListView(9527): Get MotionRecognitionManager
02-17 13:03:23.740: D/dalvikvm(9527): GC_CONCURRENT freed 194K, 6% free 13206K/13959K, paused 2ms+2ms, total 20ms
02-17 13:03:23.740: D/dalvikvm(9527): WAIT_FOR_CONCURRENT_GC blocked 9ms
02-17 13:03:23.745: D/dalvikvm(9527): WAIT_FOR_CONCURRENT_GC blocked 9ms
02-17 13:03:23.760: D/AndroidRuntime(9527): Shutting down VM
02-17 13:03:23.760: W/dalvikvm(9527): threadid=1: thread exiting with uncaught exception (group=0x41c802a0)
02-17 13:03:23.760: E/AndroidRuntime(9527): FATAL EXCEPTION: main
02-17 13:03:23.760: E/AndroidRuntime(9527): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mm/com.example.mm.MainActivity}: java.lang.NullPointerException
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.access$600(ActivityThread.java:140)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.os.Looper.loop(Looper.java:137)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.main(ActivityThread.java:4898)
02-17 13:03:23.760: E/AndroidRuntime(9527): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 13:03:23.760: E/AndroidRuntime(9527): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 13:03:23.760: E/AndroidRuntime(9527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
02-17 13:03:23.760: E/AndroidRuntime(9527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
02-17 13:03:23.760: E/AndroidRuntime(9527): at dalvik.system.NativeStart.main(Native Method)
02-17 13:03:23.760: E/AndroidRuntime(9527): Caused by: java.lang.NullPointerException
02-17 13:03:23.760: E/AndroidRuntime(9527): at com.example.mm.MainActivity.onCreate(MainActivity.java:82)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.Activity.performCreate(Activity.java:5191)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
02-17 13:03:23.760: E/AndroidRuntime(9527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
02-17 13:03:23.760: E/AndroidRuntime(9527): ... 11 more
02-17 13:03:23.955: D/dalvikvm(9527): GC_CONCURRENT freed 233K, 6% free 13394K/14215K, paused 14ms+1ms, total 44ms

Seems like there is no last known location for that location provider. This can happen, if that location provider never had a location fix.
Simply try to better work around the case where loc == null.

Related

Facebook Messenger SDK for Android: crash when sharing a URL

I need to use the Facebook Messenger SDK in an Android app. I want to send a URL, just as text. Since ShareToMessengerParams is too limited, I was forced to manually construct an intent as shown at https://developers.facebook.com/docs/messenger/android#integration_with_intents:
private static final String EXTRA_PROTOCOL_VERSION = "com.facebook.orca.extra.PROTOCOL_VERSION";
private static final String EXTRA_APP_ID = "com.facebook.orca.extra.APPLICATION_ID";
private static final int PROTOCOL_VERSION = 20150314;
private static final String YOUR_APP_ID = "[YOUR_FACEBOOK_APP_ID]";
private static final int SHARE_TO_MESSENGER_REQUEST_CODE = 1;
...
String mimeType = "text/plain";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_TEXT, [MY_STRING_URL]);
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
activity.startActivityForResult(shareIntent, SHARE_TO_MESSENGER_REQUEST_CODE);
This crashes with:
E/AndroidRuntime( 2429): FATAL EXCEPTION: main
E/AndroidRuntime( 2429): java.lang.ClassCastException: com.facebook.messaging.sharing.f cannot be cast to com.facebook.messaging.sharing.bs
E/AndroidRuntime( 2429): at com.facebook.messaging.sharing.cz.a(ShareLauncherActivity.java:294)
E/AndroidRuntime( 2429): at com.facebook.messaging.sharing.cz.onSuccess(ShareLauncherActivity.java:286)
E/AndroidRuntime( 2429): at com.google.common.f.a.q.run(Futures.java:1231)
E/AndroidRuntime( 2429): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
E/AndroidRuntime( 2429): at com.facebook.common.executors.dv.run(WrappingExecutorService.java:77)
E/AndroidRuntime( 2429): at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime( 2429): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2429): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2429): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 2429): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2429): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2429): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 2429): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 2429): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 312): Force finishing activity com.facebook.orca/com.facebook.messaging.sharing.ShareLauncherActivity
If I add:
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
it doesn't crash but since my URL is just a link and does not point to a file, I get various errors: that the content could not be found, or, if I put a fake contentUri, the real URL I want to share is not activated upon clicking. If I remove:
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
it doesn't crash either but then users who have not installed my app (from which the sharing is done) do not get the Facebook Messenger "Install" button.
How can I share a web link and at the same time have users get the "Install" and "Reply" buttons as needed?

Android studio is not showing any errors but my logcat shows that there are errors

this is my logcat-
03-23 21:02:12.573 22442-22442/the.falacermusicE/AndroidRuntime:FATAL EXCEPTION: main
android.app.SuperNotCalledException: Activity {the.falacermusic/the.falacermusic.ui.activities.HomeActivity} did not call through to super.onStart()
at android.app.Activity.performStart(Activity.java:5196)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2087)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
at android.app.ActivityThread.access$700(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4963)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
03-23 21:02:12.573 22442-22442/the.falacermusicE/AndroidRuntime:FATAL EXCEPTION: main android.app.SuperNotCalledException: Activity {the.falacermusic/the.falacermusic.ui.activities.HomeActivity} did not call through to super.onStart()
As the error states you are implementing the onStart method in your HomeActivity but you are not going throgh the super.onStart() method.

Conflict with activity tags on android manifest: Facebook and Prime31 plugins in Unity3d

I'm trying to get a project to work with both the Facebook Unity plugin and (several) Prime31 plugins. I'm trying to create my own activity that extends the Prime31 activity and also incorporates the workaround for Facebook given here: Conflict with activity tags on android manifest: Facebook and Google Play Games in Unity3d
So far, I've got a class that looks like this:
import android.content.Intent;
import android.os.Bundle;
import com.facebook.Session;
public class DQUnityPlayerActivity extends com.prime31.UnityPlayerProxyActivity
{
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
I've compiled it with javac, packed it up as a .jar file, and put it in /Assets/Plugins/Android. I modified our AndroidManifest.xml like so:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" android:installLocation="preferExternal" android:theme="#android:style/Theme.NoTitleBar" android:versionCode="1" android:versionName="1.0">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".DQUnityPlayerActivity" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
etc...
Now here's where I'm stuck: at this point, when I try to run it on my test device, the class isn't found. ADB shows me this:
E/AndroidRuntime(16863): FATAL EXCEPTION: main
E/AndroidRuntime(16863): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dqsoft.ChampHearts/com.dqsoft.ChampHearts.DQUnityPlayerActivity}: java.lang.ClassNotFoundException: com.dqsoft.ChampHearts.DQUnityPlayerActivity in loader dalvik.system.PathClassLoader[/mnt/asec/com.dqsoft.ChampHearts-1/pkg.apk]
E/AndroidRuntime(16863): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
E/AndroidRuntime(16863): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(16863): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(16863): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(16863): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(16863): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(16863): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(16863): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(16863): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(16863): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(16863): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(16863): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(16863): Caused by: java.lang.ClassNotFoundException: com.dqsoft.ChampHearts.DQUnityPlayerActivity in loader dalvik.system.PathClassLoader[/mnt/asec/com.dqsoft.ChampHearts-1/pkg.apk]
E/AndroidRuntime(16863): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime(16863): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(16863): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime(16863): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(16863): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
E/AndroidRuntime(16863): ... 11 more
Any idea what could be wrong?
You need to put your exported jar file inside Assets/Plugins/Android/ folder and make sure in your DQUnityPlayerActivity class you have this line:
package com.dqsoft.ChampHearts;

AndEngine sprite causing a force close

first time poster, new to Android programming. Using Eclipse classic, have android SDK loaded and the API. Have created a hello world app, and the text send app that follows (android dev site). Now working on a game using the Jimmaru (http://jimmaru.wordpress.com/2011/09/28/andengine-simple-android-game-tutorial/) tutorial (GLES1), using AndEngine (GLES1 as far as I can tell, didn't have a superclass of "simpleBaseGameActivity" when I looked for it. I've gotten the blank screen to show up fine, but the step to add a player sprite results in a force close on app execution/loading.
Here is my One Class (SimpleGame)
package com.example.game;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import android.view.Display;
public class SimpleGame extends BaseGameActivity {
// initiates view
private Camera mCamera;
// Main Scene
private Scene mMainScene;
private Sprite player;
// Textures
private BitmapTextureAtlas mBitmapTextureAtlas;
private TextureRegion mPlayerTextureRegion;
#Override
public Engine onLoadEngine() {
final Display display = getWindowManager().getDefaultDisplay();
int cameraWidth = display.getWidth();
int cameraHeight = display.getHeight();
mCamera = new Camera(0, 0, cameraWidth, cameraHeight);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,
new RatioResolutionPolicy(cameraWidth, cameraHeight), mCamera));
}
#Override
public void onLoadResources() {
// This places player character on screen, file is in
// assets/gfx/Player.png
mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(this.mBitmapTextureAtlas, this, "Player.png",
0, 0);
mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas);
}
#Override
public Scene onLoadScene() {
mEngine.registerUpdateHandler(new FPSLogger());
mMainScene = new Scene();
mMainScene
.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
mMainScene.attachChild(player);
final int PlayerX = this.mPlayerTextureRegion.getWidth() / 2;
final int PlayerY = (int) ((mCamera.getHeight() - mPlayerTextureRegion
.getHeight()) / 2);
player = new Sprite(PlayerX, PlayerY, mPlayerTextureRegion);
return mMainScene;
}
#Override
public void onLoadComplete() {
// TODO Auto-generated method stub
}
}
Here is my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.game"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme">
<activity android:name="SimpleGame">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Here is my LogCat File
08-21 14:14:50.116: D/dalvikvm(12704): GC_EXTERNAL_ALLOC freed 76K, 50% free 2737K/5379K, external 0K/0K, paused 33ms
08-21 14:14:50.156: D/AndEngine(12704): UpdateThread interrupted. Don't worry - this Exception is most likely expected!
08-21 14:14:50.156: D/AndEngine(12704): java.lang.InterruptedException
08-21 14:14:50.156: D/AndEngine(12704): at java.lang.Object.wait(Native Method)
08-21 14:14:50.156: D/AndEngine(12704): at java.lang.Object.wait(Object.java:358)
08-21 14:14:50.156: D/AndEngine(12704): at org.anddev.andengine.engine.Engine$State.waitUntilCanUpdate(Engine.java:722)
08-21 14:14:50.156: D/AndEngine(12704): at org.anddev.andengine.engine.Engine.yieldDraw(Engine.java:472)
08-21 14:14:50.156: D/AndEngine(12704): at org.anddev.andengine.engine.Engine.onTickUpdate(Engine.java:463)
08-21 14:14:50.156: D/AndEngine(12704): at org.anddev.andengine.engine.Engine$UpdateThread.run(Engine.java:685)
08-21 14:14:50.316: D/AndroidRuntime(12704): Shutting down VM
08-21 14:14:50.316: W/dalvikvm(12704): threadid=1: thread exiting with uncaught exception (group=0x401cc568)
08-21 14:14:50.316: E/AndroidRuntime(12704): FATAL EXCEPTION: main
08-21 14:14:50.316: E/AndroidRuntime(12704): java.lang.NullPointerException
08-21 14:14:50.316: E/AndroidRuntime(12704): at org.anddev.andengine.entity.Entity.attachChild(Entity.java:482)
08-21 14:14:50.316: E/AndroidRuntime(12704): at com.example.game.SimpleGame.onLoadScene(SimpleGame.java:71)
08-21 14:14:50.316: E/AndroidRuntime(12704): at org.anddev.andengine.ui.activity.BaseGameActivity.doResume(BaseGameActivity.java:169)
08-21 14:14:50.316: E/AndroidRuntime(12704): at org.anddev.andengine.ui.activity.BaseGameActivity.onWindowFocusChanged(BaseGameActivity.java:85)
08-21 14:14:50.316: E/AndroidRuntime(12704): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2106)
08-21 14:14:50.316: E/AndroidRuntime(12704): at android.view.View.dispatchWindowFocusChanged(View.java:3925)
08-21 14:14:50.316: E/AndroidRuntime(12704): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:665)
08-21 14:14:50.316: E/AndroidRuntime(12704): at android.view.ViewRoot.handleMessage(ViewRoot.java:1982)
08-21 14:14:50.316: E/AndroidRuntime(12704): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 14:14:50.316: E/AndroidRuntime(12704): at android.os.Looper.loop(Looper.java:130)
08-21 14:14:50.316: E/AndroidRuntime(12704): at android.app.ActivityThread.main(ActivityThread.java:3703)
08-21 14:14:50.316: E/AndroidRuntime(12704): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 14:14:50.316: E/AndroidRuntime(12704): at java.lang.reflect.Method.invoke(Method.java:507)
08-21 14:14:50.316: E/AndroidRuntime(12704): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-21 14:14:50.316: E/AndroidRuntime(12704): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-21 14:14:50.316: E/AndroidRuntime(12704): at dalvik.system.NativeStart.main(Native Method)
08-21 14:14:54.190: I/Process(12704): Sending signal. PID: 12704 SIG: 9
Any help is much appreciated, thank you.
move this line
mMainScene.attachChild(player);
to a point in between these two lines
player = new Sprite(PlayerX, PlayerY, mPlayerTextureRegion);
return mMainScene;

PackageInfo versionCode and versionName null on phone, but works on emulator

I am building a private app that will not go through the Marketplace. As a result, I need to pull the current version application (not platform) information and check with the server to see if there is an update. It works great on the emulator, but when I installed the signed APK on my Droid X, it returns null. Here is the code:
PackageInfo pInfo = null;
try {
pInfo = getPackageManager().getPackageInfo("com.rubiconproject.expenses",
PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
return;
}
String postUrl = DbAdapter.REMOTE_DB +
"/application/active-version/platform/android/version/" +
pInfo.versionCode + "." + pInfo.versionName;
EDIT:
I wrote a much smaller application, below, that displays my problem (TestingActivity.java):
package com.rubiconproject.testing;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.widget.TextView;
public class TestingActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PackageInfo pInfo = null;
try {
pInfo = getPackageManager().getPackageInfo(
"com.rubiconproject.testing", PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
return;
}
TextView tt = (TextView)findViewById(R.id.textView1);
tt.setText(pInfo.versionCode);
TextView tt2 = (TextView)findViewById(R.id.textView2);
tt2.setText(pInfo.versionName);
}
}
And the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rubiconproject.testing"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".TestingActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
adb logcat shows:
E/AndroidRuntime( 335): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rubiconproject.testing/com.rubiconproject.testing.TestingActivity}: java.lang.NullPointerException
E/AndroidRuntime( 335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
E/AndroidRuntime( 335): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
E/AndroidRuntime( 335): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 335): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
E/AndroidRuntime( 335): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 335): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 335): at android.app.ActivityThread.main(ActivityThread.java:3647)
E/AndroidRuntime( 335): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 335): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 335): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 335): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 335): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 335): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 335): at com.rubiconproject.testing.TestingActivity.onCreate(TestingActivity.java:26)
E/AndroidRuntime( 335): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 335): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
E/AndroidRuntime( 335): ... 11 more
where line 26 corresponds to:
tt.setText(pInfo.versionCode);
Does anyone know why this is happening?
Does your manifest.xml contain android:versionCode and androd:versionName attributes?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package.name"
android:versionCode="2"
android:versionName="1.1">
<application android:icon="#drawable/icon" android:label="#string/app_name">
...
</application>
</manifest>
Figured it out. The problem was between the keyboard and the chair. I was seeing null, when it fact the string was being built improperly.