• Register
Log In
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.

2.3k points

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.

4.7k points

Related questions

0 votes
1 answer 43 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 63 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 85 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 19 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 mphil 2.3k points
0 votes
1 answer 263 views
Problem : I want to input some of the details about student to my program. But when I press a save button its giving me the below listed exception error: "Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet."
asked Jan 31 jwilliam 3.9k points