I am getting the following error whenever I close my application:
FATAL EXCEPTION: main
Process: uk.cal.codename.projectnedry, PID: 24450
java.lang.RuntimeException: Unable to destroy activity {uk.cal.codename.projectnedry/uk.CompanyScope.CompanyNavigationActivity.CompanyNavigationActivity}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4203)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4221)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.set(ArrayList.java:427)
at android.support.v4.app.FragmentManagerImpl.makeInactive(FragmentManager.java:1662)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1452)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:2951)
at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:271)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:390)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
at uk.genericmodelviewpresenter.GenericMvpActivity.onDestroy(GenericMvpActivity.java:96)
at uk.CompanyScope.CompanyNavigationActivity.CompanyNavigationActivity.onDestroy(CompanyNavigationActivity.java:523)
at android.app.Activity.performDestroy(Activity.java:6881)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1153)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4190)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4221)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1538)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
The only parts that touch code that I have written are:
CompanyNavigationActivity:
#Override
public void onDestroy() {
super.onDestroy();
getSpecificImpOfGenericPresenter().closeRealm();
}
and its superclass GenericMvpActivity:
#Override
public void onDestroy() {
super.onDestroy();
//Unbind Butterknife bindings
if(mUnbinder!=null) {
mUnbinder.unbind();
}
}
From looking at the stacktrace I can see it is something fragment related, but this is within the Android code. This CompanyNavigationActivity does at times contain a number of fragments, but the error occurs whether they are created or not.
Any ideas as to what the cause is?
EDIT 1
The closeRealm method in the presenter class, simply removes listeners and closes the presenters instance of realm.
public void closeRealm() {
this.mRealmDatabase.getInstance().removeAllChangeListeners();
this.mRealmDatabase.close();
}
EDIT 2
Upon further testing it seems that if I create fragments held within a viewpager in my CompanyNavigationActivity this error does not occur. It seems to occur only when there are no fragments present within the activity.
EDIT 3
I have narrowed it down to a particular method, which is starting a foreground service. More specifically, the startService call.
/**
* If foreground location service is not running, start it
*/
private void startLocationService() {
if (!ForegroundLocationService.IS_SERVICE_RUNNING) {
Intent service = new Intent(getSpecificImpOfGenericView().getApplicationContext(), ForegroundLocationService.class);
service.setAction(ServiceConstants.ACTION.STARTFOREGROUND_ACTION);
ForegroundLocationService.IS_SERVICE_RUNNING = true;
getSpecificImpOfGenericView().getApplicationContext().startService(service);
}
}
Surely a foreground request should remain in the foreground, as a separate service, and not affect the destruction of the activity that started them?
You should do all the job before super.onDestroy();
Destroy the instance specific resources first, before destroying superclass resources that the instance specific resources may depend upon makes sense.
Related
When the orientation of app change this error is occur kindly help me
W/ActionBarDrawerToggle: DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.explore_kpk, PID: 24892
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.explore_kpk/com.example.explore_kpk.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5389)
at android.app.ActivityThread.access$1200(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1803)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
***Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference***
***at com.example.explore_kpk.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:6877)***
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5389)
at android.app.ActivityThread.access$1200(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1803)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
I/Process: Sending signal. PID: 24892 SIG: 9
This is code in which error pointing**
at com.example.explore_kpk.MainActivity.onCreate(MainActivity.java:121)
RecyclerView recyclerView=(RecyclerView)findViewById(R.id.recyler_view);
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(this, recyclerList);
long seed = System.nanoTime();
Collections.shuffle(recyclerList, new Random(seed));
GridLayoutManager gridLayoutManager=new GridLayoutManager(this, mNoOfColumns);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(recyclerViewAdapter);
Your exception is saying that you are trying to use setLayoutManager on null object reference. This means that your recylcerView is null at the moment. I don't see your whole code so I can't give you an instant solution. What I can say for you is that each time the screen orientation is changed your current activity will be destroyed and called again. So, onCreate will be called again and everything else like you just started new Activity. Sometimes issues happen here so there is few options on how to handle these events.
Retaining an object during a configuration change
What this means is for you to keep your data while screen rotation is happening. This can be done with Bundle but if you have a large set of data then it is better to use the ViewModel object. How to do this check here:
Retaining an object during a configuration change | Android Developers
ViewModel Guide
Helpful answer on SO
Handling the configuration change yourself
This other option comes with big CAUTION. Consider this as a last resort when you really need to avoid restarts because of a configuration change. What this does is preventing your activity from the restart. If you can't save your instance then I would recommend doing this but first, try to play with ViewModel and Bundles to fix this issue.
Handling the configuration change yourself | Documentation
How to do this?
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout" />
add android:configChanges line to your AndroidManifest.xml inside your <activity/> tag.
My problem is quite a troublesome one, i made an app on Android Studio that has a TextView that displays the Firebase registration token upon launch (I'm still new to Firebase and Android Studio, i'm experimenting), i've been building APK files of my app to test it on my phone since Android Studio doesn't detect my phone when it's hooked to my laptop for some reason and i can't use emulation because my laptop is old (i think it doesn't support virtualization), so whenever i try to launch my app on my phone i get the equivalent of MyApp stopped working in French and i don't know how to view the crash log files.
tl;dr i wanna know what's causing my app to crash
MainActivity.java
package com.gci.gestioncapteursincendie;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
public class MainActivity extends AppCompatActivity {
private TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView= findViewById(R.id.textViewToken);
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
#Override
public void onComplete(#NonNull Task<InstanceIdResult> task) {
if(task.isSuccessful()){
String token = task.getResult().getToken();
textView.setText("Token : " + token);
}
else
{
textView.setText("Token Not Generated");
}
}
});
}
}
Edit: i managed to run my app on my phone through Android Studio by downloading the right drivers, i checked the logcat when i ran it and i got this:
03-31 18:55:45.069 8855-8855/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gci.gestioncapteursincendie, PID: 8855
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gci.gestioncapteursincendie/com.gci.gestioncapteursincendie.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.gci.gestioncapteursincendie. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.gci.gestioncapteursincendie. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.0.1:219)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at com.gci.gestioncapteursincendie.MainActivity.onCreate(MainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Edit 2:
I added the following line of code referred by user Riley Manda:
FirebaseApp.initializeApp(this);
in onCreate() method and i get this error now:
log trace:
03-31 19:10:19.203 11562-11562/com.gci.gestioncapteursincendie E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gci.gestioncapteursincendie, PID: 11562
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gci.gestioncapteursincendie/com.gci.gestioncapteursincendie.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.gci.gestioncapteursincendie. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.gci.gestioncapteursincendie. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.0.1:219)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at com.gci.gestioncapteursincendie.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Edit 3: I'm making another thread about this problem since it seems like the thread has drifted away from its original purpose, thanks everyone for answering.
Connect your app to Crashlytics,this way you will receive crash emails that will lead you to the exact issue thats causing your app to crash.
Follow the instructions on firebase to setup crashlytics for your app in Android Studio.And each time your app crashes, you will receive an email from Crashlytics:
This way, each time your app crashes from your physical devices notification email from Crashlytics is automatically sent to your email indicating the exact line of code/issue that's causing your app to crash.
Based on your crashLog:
You have to initialise firebase in your activity:
Add this to your activity:
FirebaseApp.initializeApp(this);
In your onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayout);
FirebaseApp.initializeApp(this);
Add this FirebaseApp.initializeApp(this);just after setContentView(R.layout.yourlayout); or before you make any connections to firebase
Also for your device not showing in android studio
first enable developers Options On your Phone https://www.digitaltrends.com/mobile/how-to-get-developer-options-on-android/
Enable Usb Debugging in the developers Options of your Phone settings
Secondly install an adb driver on your System and try reconnecting your device
Accept the prompt on your phone that asks if you want to trust your system and it should work
I have an application that creates an Intent when selecting item menu, but the first time the user clicks this button, the app crashes with the following stack trace.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.systemsat.monitriip, PID: 17818
java.lang.NoClassDefFoundError: br.com.systemsat.monitriip.activity.ConfigurationActivity
at br.com.systemsat.monitriip.activity.MainActivity.onOptionsItemSelected(MainActivity.java:212)
at android.app.Activity.onMenuItemSelected(Activity.java:2912)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:421)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:188)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:663)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:810)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:957)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:947)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:155)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Below is my Activity declaration inside AndroidManifest.xml:
<activity
android:name=".activity.ConfigurationActivity"
android:parentActivityName=".activity.MainActivity">
</activity>
Also, below is the line that is accused to be the cause of the problem by the call stack:
Intent hashCodeIntent = new Intent(getApplicationContext(), ConfigurationActivity.class);
Some answers found in StackOverflow pointed me that clean and rebuild would do the trick but I've tried without any luck. I have also tried adding MultiDex to gradle file as well as to my custom Application class, but that also resulted in a no go.
Could someone else have any insights as to what I might have done wrong? What is really intriguing is that this error only happens on the first time the user clicks the "Configuration" screen button. After the app crashes, the user can reopen it and click the button normally.
Thank you in advance.
UPDATE
I have forgot to mention that Android Monitor also logs the following info right before the crash:
Rejecting re-init on previously-failed class java.lang.Class<br.com.systemsat.monitriip.activity.ConfigurationActivity>
UPDATE 2
Here is my onOptionsItemSelected method:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_action_config:
Intent hashCodeIntent = new Intent(this, ConfigurationActivity.class);
hashCodeIntent.putExtra("isConfigurationCall", true);
startActivity(hashCodeIntent);
break;
}
return true;
}
UPDATE 3
I have just generated an apk for testing purposes and the error did not show. Maybe it has something to do with debuging? Or even something to do with gradle version? I currently use the last version of gradle.
Try to change getAplicationContext() for getActivity()
Sometimes getAplicationContext returns null.
I'm trying to retrieve the location of the device calling the method connect of the class LocationClient in my activity, however when the call is made the system crashes with the following exception:
**FATAL EXCEPTION: main
Process: com.unipagossales, PID: 3833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.unipagossales/com.unipagossales.app.merchants.MerchantFragmentActivity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.location.internal.GoogleLocationManagerService.START }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.location.internal.GoogleLocationManagerService.START }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1773)
at android.app.ContextImpl.bindService(ContextImpl.java:1751)
at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
at com.google.android.gms.internal.v.a(Unknown Source)
at com.google.android.gms.internal.u.connect(Unknown Source)
at com.google.android.gms.location.LocationClient.connect(Unknown Source)
at com.unipagossales.app.merchants.MerchantFragmentActivity.onStart(MerchantFragmentActivity.java:122)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
at android.app.Activity.performStart(Activity.java:5949)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
... 10 more
**
This is the way I create my LocationClient:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.merchant_activity);
...
// Create a new global location parameters object
locationRequest = LocationRequest.create();
locationRequest.setInterval(Constants.UPDATE_INTERVAL_MILLISECONDS);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setFastestInterval(Constants.FAST_INTERVAL_CEILING_MILLISECONDS);
// Initialize the location client
locationClient = new LocationClient(this, new LocationClientConnectionCallbacks(), new LocationClientOnConnectionFailedListener());
}
#Override
protected void onStart() {
super.onStart();
...
locationClient.connect();
...
}
Changing the target SDK version to "19" helped me.
This problem is related to the fact that Android VM is not being able in runtime to find the definition of the action act=com.google.android.location.internal.GoogleLocationManagerService.START in Google Play Services.
You will need to set your Google Play Services following the next blog:
http://mflerackers.wordpress.com/2014/09/09/noclassdeffounderror-for-googleplayservicesutil/
Then you will need to increment the VM values in eclipse.ini, follow this one:
Unable to execute dex: GC overhead limit exceeded in Eclipse
This should fix your exception collaterally.
I have an activity, LookingForGPS, that starts another activity, Run. After starting Run, LookingForGPS doesn't finish, but rather continually updates some TextViews in Run:
Run run = new Run();
if(runHasBeenStarted)run.getAndSetValues(someParameters, this);
To my understanding, this returns the LookingForGPS activity. However, after a while (when the parameters are a certain value) I want to start a new activity, PostRun. The following method is called from the Run instance's getAndSetValues:
private void killEverythingAndProceed(Context context){
Intent finishRun = new Intent(context, PostRun.class);
//putting some extras into the intent
startActivity(finishRun);
}
I then get a NullPointerException at the line of startActivity:
11-17 08:34:33.647 2472-2472/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: lv.rv1g.kj0112.forward, PID: 2472
java.lang.NullPointerException
at android.app.Activity.startActivityForResult(Activity.java:3424)
at android.app.Activity.startActivityForResult(Activity.java:3385)
at android.app.Activity.startActivity(Activity.java:3627)
at android.app.Activity.startActivity(Activity.java:3595)
at lv.rv1g.kj0112.forward.Run.killEverythingAndProceed(Run.java:143)
at lv.rv1g.kj0112.forward.Run.getAndSetValues(Run.java:88)
at lv.rv1g.kj0112.forward.LookingForGPS.onLocationChanged(LookingForGPS.java:100)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)
at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:224)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
What am I doing horribly wrong? I guess it's my lack of knowledge about object-oriented programming that's causing this. It's not the extras causing it, and the context should be correct as well, as it works for another method from the same instance.
Edit: detailed explanation
The LookingForGPS activity has a LocationManager (not using a service because it has some limitations that are too complicated for me to work around). Each time onLocationChanged is called, the Run activity is instantiated (I check whether it has actually been started first, it gets started by the user independetly of the LocationManager), and the getAndSetValues method inside Run is called, giving a bunch of parameters. getAndSetValues then performs some calculations and updates some TextViews in the Run activity (which all works fine). A calculation is also performed to see whether a certain condition has been met. If it has been, the postRun activity is supposed to be started, which is when I run into the exception above.
Here's the problem:
Run run = new Run();
Looks like Run is an Activity. Never instantiate activities with new - you cannot use activities instantiated such way for anything you'd want to use an activity for. For example, to be used as a Context for startActivity().
Either use an Activity instance that has been set up by the system for you, or use an Intent to launch a new activity instance.