尽管实现了onPause(),但已经管理了ID为0的GoogleApiClient错误

时间:2019-02-10 00:01:17

标签: java android android-activity google-places-api

当单击Cardview时,我的应用程序将显示开始活动,该活动将在Recycler视图中显示附近的地方。但是,每当我单击cardview时,都会出现以下错误。当我在NeighborhoodActivity.java中注释public class StackX { private final int maxSize; private final long[] stackArray; private int top; public StackX(final int size) { maxSize = size; stackArray = new long[maxSize]; top = -1; } /** Puts an item on top of the stack. */ public void push(final long value) { if (isFull()) { throw new UnsupportedOperationException("Stack is full"); } stackArray[++top] = value; } /** Takes an item from top of the stack. */ public long pop() { if (isEmpty()) { throw new UnsupportedOperationException("Stack is empty"); } return stackArray[top--]; } /** Peeks an item at top of the stack. */ public long peek() { return stackArray[top]; } /** Returns {@code true} if stack is empty. */ public boolean isEmpty() { return top == -1; } /** Returns {@code true} if stack is full. */ public boolean isFull() { return top == maxSize - 1; } } 时,程序不会崩溃。这是可能的,因为nearByPlace(“ restaurant”)也使用相同的ID,我该如何解决

  

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.android.sunshine / com.example.android.sunshine.MainActivity}:java.lang.IllegalStateException:已管理ID为0的GoogleApiClient

Error Logcat

ItemOneFragment.Java

public class Main {
    public static void main(final String[] args) {
        final StackX stackX = new StackX(5);
        stackX.push(20);
        stackX.push(40);
        stackX.push(60);
        stackX.push(80);

        removeDownTo(stackX, 60);

        // Prints remaining elements
        while (!stackX.isEmpty()) {
            System.out.println(stackX.pop());
        }

        System.out.println(stackX.isEmpty());
    }

    private static void removeDownTo(
            final StackX stack,
            final long downTo) {
        while (!stack.isEmpty()) {
            if (stack.peek() == downTo) {
                return;
            }

            stack.pop();
        }
    }
}

NearbyActivity.Java

nearByPlace("restaurant")

1 个答案:

答案 0 :(得分:0)

是的,您已经为自己的活动正确实施了onPause,但没有为您的Fragment实施。

在Fragment内的init方法中,创建一个新的GoogleApiClient。这与您的Activity中的代码不同,在onPause中,您正确地实现了onPause

因此,解决该问题的方法应该是为您的Fragment实现//toggle hitbox on and off public void EnableHitbox(bool enabled) { coll.enabled = enabled; Debug.Log("Hitbox enabled: " + enabled); } //check for collisions with hurtboxes private void OnTriggerEnter2D(Collider2D collision) { if (collision.transform.tag == "Hurtbox" && collision.transform.parent.transform.tag == "Enemy") { Debug.Log("Hitbox hit enemy"); } }

我希望这能解决您的问题