AndEngine sprite causing a force close - andengine

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;

Related

StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation warning on pre launched .aab release

I have been struggling with this issue but stil no answer I have found by googling. After applying sslcommerz payment gateway getting the warning. Though it seems to be a related question but no proper solution is available on github or stackoverflow. Here I attached warning log.
Note : both .aab and .apk file are doing well before play store upload
Stacktrace 1:
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/util/LongArray;->get(I)J
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredMethodInternal(Native Method)
at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
at java.lang.Class.getMethod(Class.java:2063)
at java.lang.Class.getMethod(Class.java:1690)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:475)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:429)
at io.flutter.view.AccessibilityViewEmbedder.<init>(AccessibilityViewEmbedder.java:70)
at io.flutter.view.AccessibilityBridge.<init>(AccessibilityBridge.java:352)
at io.flutter.embedding.android.FlutterView.attachToFlutterEngine(FlutterView.java:912)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onCreateView(FlutterActivityAndFragmentDelegate.java:303)
at io.flutter.embedding.android.FlutterActivity.createFlutterView(FlutterActivity.java:520)
at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:414)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:2)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Stacktrace 2:
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredMethodInternal(Native Method)
at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
at java.lang.Class.getMethod(Class.java:2063)
at java.lang.Class.getMethod(Class.java:1690)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:446)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:429)
at io.flutter.view.AccessibilityViewEmbedder.<init>(AccessibilityViewEmbedder.java:70)
at io.flutter.view.AccessibilityBridge.<init>(AccessibilityBridge.java:352)
at io.flutter.embedding.android.FlutterView.attachToFlutterEngine(FlutterView.java:912)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onCreateView(FlutterActivityAndFragmentDelegate.java:303)
at io.flutter.embedding.android.FlutterActivity.createFlutterView(FlutterActivity.java:520)
at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:414)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:2)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Stacktrace 3:
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray;
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredField(Native Method)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:471)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:429)
at io.flutter.view.AccessibilityViewEmbedder.<init>(AccessibilityViewEmbedder.java:70)
at io.flutter.view.AccessibilityBridge.<init>(AccessibilityBridge.java:352)
at io.flutter.embedding.android.FlutterView.attachToFlutterEngine(FlutterView.java:912)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onCreateView(FlutterActivityAndFragmentDelegate.java:303)
at io.flutter.embedding.android.FlutterActivity.createFlutterView(FlutterActivity.java:520)
at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:414)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:2)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Stacktrace 4:
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredMethodInternal(Native Method)
at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
at java.lang.Class.getMethod(Class.java:2063)
at java.lang.Class.getMethod(Class.java:1690)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:451)
at io.flutter.view.AccessibilityViewEmbedder$ReflectionAccessors.<init>(AccessibilityViewEmbedder.java:429)
at io.flutter.view.AccessibilityViewEmbedder.<init>(AccessibilityViewEmbedder.java:70)
at io.flutter.view.AccessibilityBridge.<init>(AccessibilityBridge.java:352)
at io.flutter.embedding.android.FlutterView.attachToFlutterEngine(FlutterView.java:912)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onCreateView(FlutterActivityAndFragmentDelegate.java:303)
at io.flutter.embedding.android.FlutterActivity.createFlutterView(FlutterActivity.java:520)
at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:414)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:2)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

exception about weex_sdk:0.18.0

recently encountered an occasional problem
all of logcat:
com.taobao.weex.ui.flat.FlatGUIContext.getFlatComponentAncestor(com.taobao.weex.ui.component.WXComponent)' on a null object reference
at com.taobao.weex.ui.component.WXComponent.setComponentLayoutParams(WXComponent.java:559)at com.taobao.weex.ui.component.WXComponent.setLayout(WXComponent.java:551)
at com.taobao.weex.ui.RenderActionContextImpl.setLayout(RenderActionContextImpl.java:82)
at com.taobao.weex.ui.WXRenderManager.setLayout(WXRenderManager.java:150)
at com.taobao.weex.dom.DOMActionContextImpl$ApplyUpdateConsumer$1.execute(DOMActionContextImpl.java:276)
at com.taobao.weex.ui.WXRenderManager$1.run(WXRenderManager.java:104)
at com.taobao.weex.common.WXThread$SafeRunnable.run(WXThread.java:48)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6114)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)

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.

Google Maps API V2 android app on API level 8 up to 17

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.

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.