• Register
0 votes

Problem :

Now a days I am learning Android Programming. I am facing below error message while trying to implement the logout functionality for the Google Sign-In for the Android:

“Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet.”

The crash always occurs in my Java file where I am trying to call the signOut() method.

Below is my java code causing error

private void mygoogleSignOut(){
    myGoogleApiClient = App.getInstance().getClient();

I am struggling to find solution on it since yesterday.

8 4 2
2,300 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I know you are learning Android Programming. You can try below solution to fix the error.

I can tell you the actual cause of your error is not at the object creation but it is present at more than one place it is usually found at "enableAutoManage" invocation while Building your Client object.

I have found the required API doc.  it clearly suggests that it will automatically do a life cycle management just by calling the methods on the onStart & onStop methods of your activity.

So if you are planning to use the same object across all the activities then you must avoid calling the "enableAutoManage" and invoke your apiObject.connect(use in onStart of activity) and the apiObject.disconnect() (use in onStop of activity).

This worked for me so I am very sure that it will work for you too.

5 2 1
4,980 points

Related questions

0 votes
1 answer 76 views
Problem : While executing Android code getting below error java.lang.illegalstateexception could not execute method of the activity
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 120 views
Problem : I am getting bellow error while learning android and trying to make a semi-useful app. java.lang.illegalstateexception: could not execute method for android:onclick
asked Oct 19, 2019 peterlaw 6.9k points
0 votes
1 answer 61 views
Problem : I am getting bellow error while I'm trying to setup an Android dev environment on Mac error:buildtools 24.0.2 requires java 1.8 or above. current jdk version is 1.7.
asked Oct 19, 2019 peterlaw 6.9k points
0 votes
1 answer 352 views
Problem: Currently I am trying to learn Android programming. I am also trying to make an android studio project and I am learning to debug my Android application. While running my application everything works perfectly fine, but if I try to debug it then I face below error: “Could not connect to remote process. Aborting debug session.” How can I fix this Android issue?
asked Sep 1, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 15 views
Problem: I am very new to Android and Haxm. Now I am facing a very inexplicable error. Virtualization is already turned on .I have installed the haxm successfully. Still if I try to run the application then all of sudden the below error is ... requires hardware acceleration! Please ensure Intel HAXM is properly installed and usable. CPU acceleration status: HAX kernel module is not installed!
asked Aug 26, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 34 views
Problem : I am new to Android Programming. I have started working on it recently. Now I am facing below error message. Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.transform.api.TransformException: com.android.ide.common. ... have added too many Gradle dependencies, but all those dependencies are important for my project. Have anybody faced this issue?
asked Feb 28, 2020 mphil 2.3k points
0 votes
1 answer 149 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17, 2020 game 4.6k points