PackageInfo versionCode and versionName null on phone, but works on emulator - android-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.

Related

how to solve FATAL EXCEPTION: AsyncTask #2 in flutter

I am using video_editor package in flutter. When I at debug mode it works and no error but when I release the apk, the apps clash and show the error :
D/flutter-ffmpeg(10753): Getting media information for /data/user/0/com.example.apps/cache/file_picker/Screenrecorder-2021-05-19-15-53-57-515.mp4.
E/AndroidRuntime(10753): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(10753): Process: com.example.apps, PID: 10753
E/AndroidRuntime(10753): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(10753): at android.os.AsyncTask$4.done(AsyncTask.java:399)
E/AndroidRuntime(10753): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(10753): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(10753): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(10753): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(10753): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(10753): at java.lang.Thread.run(Thread.java:919)
E/AndroidRuntime(10753): Caused by: java.lang.UnsatisfiedLinkError: Bad JNI version returned from JNI_OnLoad in "/data/app/com.example.apps-QO20kuBv0uYvExYVArrO7A==/lib/arm64/libmobileffmpeg.so": 0
E/AndroidRuntime(10753): at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
E/AndroidRuntime(10753): at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
E/AndroidRuntime(10753): at java.lang.System.loadLibrary(System.java:1667)
E/AndroidRuntime(10753): at com.arthenica.mobileffmpeg.Config.<clinit>(Unknown Source:148)
E/AndroidRuntime(10753): at com.arthenica.mobileffmpeg.Config.nativeFFprobeExecute(Native Method)
E/AndroidRuntime(10753): at com.arthenica.mobileffmpeg.f.a(Unknown Source:0)
E/AndroidRuntime(10753): at com.arthenica.mobileffmpeg.f.b(Unknown Source:0)
E/AndroidRuntime(10753): at com.arthenica.mobileffmpeg.f.a(Unknown Source:48)
E/AndroidRuntime(10753): at c.b.a.a.c.a(Unknown Source:21)
E/AndroidRuntime(10753): at c.b.a.a.c.doInBackground(Unknown Source:2)
E/AndroidRuntime(10753): at android.os.AsyncTask$3.call(AsyncTask.java:378)
E/AndroidRuntime(10753): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(10753): ... 3 more
Does anyone know how to solve this error?
Please check that all required dependencies are included within "dependencies:" in pubspec.yaml. Dependencies declared inside "dev_dependencies:" are not included in released app
Add the following entries into your proguard-rules.pro file. If you don't have this file you can create and put in app folder.
-keep class com.arthenica.mobileffmpeg.Config {
native <methods>;
void log(long, int, byte[]);
void statistics(long, int, float, float, long , int, double, double);
}
-keep class com.arthenica.mobileffmpeg.AbiDetect {
native <methods>;
}

How to save assets images in phones gallery? Using gallery_saver plugin

Hey I am using https://pub.dev/packages/gallery_saver plugin and I have assets images in my app using I am trying to save in phones gallery. I am doing something like this but failed. Anyone pls help me
void _saveNetworkImage() async {
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
String path = tempPath + '/' + widget.imagePath; // widget.imgPath = "assets/images/my image.jpg";
print('ddd' + path);
GallerySaver.saveImage(path).then((bool success) {
setState(() {
print('Image is saved');
});
});
}
}
I am calling ablove function as :
floatingActionButton: FloatingActionButton.extended(
onPressed: _saveNetworkImage,
icon: Icon(Icons.save),
label: Text('Gallery'),
backgroundColor: Colors.white54,
foregroundColor: Colors.black,
)
Here my function is running but giving error
D/ViewRootImpl#cbdf65[MainActivity]( 3518): ViewPostIme pointer 1
I/flutter ( 3518): path/data/user/0/com.thesachin.template/cache
I/flutter ( 3518): ddd/data/user/0/com.thesachin.template/cache/assets/images/aaj nhi kal karenge.jpg
E/AndroidRuntime( 3518): FATAL EXCEPTION: DefaultDispatcher-worker-1
E/AndroidRuntime( 3518): Process: com.thesachin.template, PID: 3518
E/AndroidRuntime( 3518): java.io.FileNotFoundException: /data/user/0/com.thesachin.template/cache/assets/images/aaj nhi kal karenge.jpg (No such file or directory)
E/AndroidRuntime( 3518): at java.io.FileInputStream.open0(Native Method)
E/AndroidRuntime( 3518): at java.io.FileInputStream.open(FileInputStream.java:231)
E/AndroidRuntime( 3518): at java.io.FileInputStream.<init>(FileInputStream.java:165)
E/AndroidRuntime( 3518): at carnegietechnologies.gallery_saver.FileUtils.getBytesFromFile(FileUtils.kt:216)
E/AndroidRuntime( 3518): at carnegietechnologies.gallery_saver.FileUtils.insertImage(FileUtils.kt:47)
E/AndroidRuntime( 3518): at carnegietechnologies.gallery_saver.GallerySaver$saveMediaFile$1$success$1.invokeSuspend(GallerySaver.kt:69)
E/AndroidRuntime( 3518): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime( 3518): at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
E/AndroidRuntime( 3518): at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
E/AndroidRuntime( 3518): at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
E/AndroidRuntime( 3518): at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
D/ViewRootImpl#cbdf65[MainActivity]( 3518): MSG_WINDOW_FOCUS_CHANGED 0 1
D/InputMethodManager( 3518): prepareNavigationBarInfo() DecorView#460d1a9[MainActivity]
D/InputMethodManager( 3518): getNavigationBarColor() -855310
I/Process ( 3518): Sending signal. PID: 3518 SIG: 9
Lost connection to device.
Finally got it with https://pub.dev/packages/image_gallery_saver. Here is my working code:
void _saveNetworkImage() async {
final bytes = await rootBundle.load(widget.imagePath); // imagePath like "assets/images/my_image.jpg"
Uint8List clockBytes = bytes.buffer.asUint8List();
final result = ImageGallerySaver.saveImage(clockBytes);
print(result);
}
}

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?

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;

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.