简体   繁体   English

Android应用程序崩溃一旦重新打开

[英]Android App Crashes Once Reopened

I'm not only new to Android Studio, I'm new to programming in general (I've been slowly teaching myself what I can the past year or so as a hobby). 我不仅是Android Studio的新手,我是一般的编程新手(我一直在慢慢地教我自己过去一年左右的爱好)。

I've run into an issue with my Android app that I can't find an answer to - even though I know many people have asked similar questions, I can't seem to understand the solution enough to adapt it to my particular problem. 我遇到了一个我无法找到答案的Android应用程序的问题 - 尽管我知道很多人都提出了类似的问题,但我似乎无法理解解决方案足以使其适应我的特定问题。 When compiled, my app will run fine and does everything I want it to do "correctly" (except for a small thing with the toolbar but I'll get to that later haha). 编译时,我的应用程序将运行良好,并做我想要它“正确”做的一切(除了工具栏的小东西,但我会稍后到达哈哈)。

The one thing it does NOT do is open correctly after I've closed it. 它没有做的一件事是在我关闭之后正确打开。 I can go to the home screen and back to the app, but if I close the app altogether and try to reopen is says it "keeps stopping." 我可以转到主屏幕并返回应用程序,但是如果我完全关闭应用程序并尝试重新打开则说它“一直停止”。

Now, I think it would be useful to give you my code (there are only two activities in this app) and my "logcat". 现在,我认为给你我的代码(这个应用程序中只有两个活动)和我的“logcat”是有用的。 However, I'm currently trying to read-up and understand how to retrieve my "logcat" in the first place haha so hopefully I'll have that here soon. 但是,我现在正在尝试阅读并了解如何首先检索我的“logcat”哈哈,所以希望我很快就能在这里找到它。

From my readings my understanding is that my problem is either with the global variables I'm declaring or something with the button ID's when I make buttons dynamically. 根据我的阅读,我的理解是我的问题是我正在声明的全局变量或者当我动态制作按钮时按钮ID的问题。 I run into people having issues with their "Threads" but I'm having trouble connecting that to my particular position. 我遇到了与他们的“线程”有问题的人,但我无法将其与我的特定位置联系起来。 However, if any of these are the issue, I'm having a hard time understanding what the issue actually is. 但是,如果其中任何一个是问题,我很难理解问题究竟是什么。

Here's my main activity... 这是我的主要活动......

package com.example.getcoins;

import android.content.Intent;
import android.icu.text.DecimalFormat;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.PointsGraphSeries;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    int intialCoins = 21;
    int coins;
    int buttonColor =  android.graphics.Color.rgb(0, 150, 150);
    int textColor =  android.graphics.Color.rgb(255, 255, 255);
    ArrayList<Integer> coinsOverTime = new ArrayList<Integer>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        setSupportActionBar(myToolbar);

        Intent intent = getIntent();
        coins = intent.getIntExtra("COINS", 1);

        if (intent.getExtras() != null)
        {
            Boolean winner = intent.getBooleanExtra("WINNER", true);
            int gambleamount = intent.getIntExtra("GAMBLE", 1);
            Bundle bundle = intent.getExtras();
            coinsOverTime = bundle.getIntegerArrayList("COIN_HISTORY");

            if (winner == true)
            {
                coins = coins + gambleamount;
                coinsOverTime.add(coins);
            }

            if (winner == false && gambleamount == 1)
            {
                coins = coins;
                coinsOverTime.add(coins);
            }

            else if(winner == false)
            {
                coins = coins - gambleamount;
                coinsOverTime.add(coins);
            }
        }

        else
        {
            coins = intialCoins;
            coinsOverTime.add(coins);
        }

        String number = Integer.toString(coins);
        double amount = Double.parseDouble(number);
        DecimalFormat formatter = new DecimalFormat("#,###");
        String formatted = formatter.format(amount);

        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setText(formatted);

        GraphView graph = (GraphView) findViewById(R.id.graph);
        PointsGraphSeries<DataPoint> series = new PointsGraphSeries<>(generateData());
        graph.addSeries(series);
        series.setShape(PointsGraphSeries.Shape.POINT);
        graph.getViewport().setXAxisBoundsManual(true);
        graph.getViewport().setMinX(0);
        graph.getViewport().setMaxX(coinsOverTime.size());

        if (coins >= 0 && coins < 101)
        {
            Button getCoinButton = addButton("Get 1 coin");
            getCoinButton.setId(R.id.one);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getOneCoin(v);
                }
            });
        }

        if (coins >= 11 && coins < 501)
        {
            Button getCoinButton = addButton("Get 10 coins");
            getCoinButton.setId(R.id.ten);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getTenCoins(v);
                }
            });
        }

        if (coins >= 21 && coins < 2001)
        {
            Button getCoinButton = addButton("Get 20 coins");
            getCoinButton.setId(R.id.twenty);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getTwentyCoins(v);
                }
            });
        }

        if (coins >= 101 && coins < 5001)
        {
            Button getCoinButton = addButton("Get 100 coins");
            getCoinButton.setId(R.id.one_hundred);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getOneHundredCoins(v);
                }
            });
        }

        if (coins >= 501 && coins < 10001)
        {
            Button getCoinButton = addButton("Get 500 coins");
            getCoinButton.setId(R.id.five_hundred);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getFiveHundredCoins(v);
                }
            });
        }

        if (coins >= 2001)
        {
            Button getCoinButton = addButton("Get 2,000 coins");
            getCoinButton.setId(R.id.two_thousand);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getTwoThousandCoins(v);
                }
            });
        }

        if (coins >= 5001)
        {
            Button getCoinButton = addButton("Get 5,000 coins");
            getCoinButton.setId(R.id.five_thousand);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getFiveThousandCoins(v);
                }
            });
        }

        if (coins >= 10001)
        {
            Button getCoinButton = addButton("Get 10,000 coins");
            getCoinButton.setId(R.id.ten_thousand);
            getCoinButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    getTenThousandCoins(v);
                }
            });
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.action_items, menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.rules:
                // User chose the "Settings" item, show the app settings UI...
                return true;

            case R.id.action_settings:
                // User chose the "Favorite" action, mark the current item
                // as a favorite...
                return true;

            case android.R.id.home:
                return true;

            default:
                // If we got here, the user's action was not recognized.
                // Invoke the superclass to handle it.
                return super.onOptionsItemSelected(item);
        }
    }




    public void getOneCoin(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 1);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getTenCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 10);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getTwentyCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 20);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getOneHundredCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 100);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getFiveHundredCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 500);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getTwoThousandCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 2000);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getFiveThousandCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 5000);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void getTenThousandCoins(View view){
        Intent intent = new Intent(this, gamble.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
        intent.putExtra("GAMBLE", 10000);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public Button addButton(String name)
    {
        LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
        Button newCoinButton = new Button(this);
        newCoinButton.setText(name);
        newCoinButton.setTextSize(30);
        //newCoinButton.setBackgroundColor(buttonColor);
        newCoinButton.setTextColor(textColor);
        //newCoinButton.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        linearLayout.addView(newCoinButton);

        return newCoinButton;
    }

    public DataPoint[] generateData()
    {
        int size = coinsOverTime.size();
        DataPoint[] values = new DataPoint[size];
        for (int i=0; i<size; i++)
        {
            int y1 = coinsOverTime.get(i);
            DataPoint v = new DataPoint(i, y1);
            values[i] = v;
        }

        return values;
    }
}

and here's the Gamble activity it talks to... 这是与之交谈的赌博活动......

package com.example.getcoins;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;

public class gamble extends AppCompatActivity {

    ArrayList<Integer> buttonValues = getButtonValues();
    //ArrayList<Integer> coinHistory = getCoinHistory();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gamble);
        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        setSupportActionBar(myToolbar);
        ActionBar ab = getSupportActionBar();
        ab.setDisplayHomeAsUpEnabled(false);

        TextView textViewLeft = (TextView) findViewById(R.id.textView2);
        TextView textViewRight = (TextView) findViewById(R.id.textView3);
        TextView textViewCoins = (TextView) findViewById(R.id.textView4);

        textViewCoins.setText("Good Luck!");


        if (buttonValues.get(0) == 0)
        {
            textViewLeft.setText("Winner");
        }

        else
        {
            textViewLeft.setText("Loser");
        }

        if (buttonValues.get(1) == 0)
        {
            textViewRight.setText("Winner");
        }

        else
        {
            textViewRight.setText("Loser");
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.action_items, menu);
        return true;
    }

    public ArrayList<Integer> getButtonValues()
    {
        ArrayList<Integer> buttonvalues = new ArrayList<Integer>();
        buttonvalues.add(0);
        buttonvalues.add(1);
        Collections.shuffle(buttonvalues);
        return buttonvalues;
    }

    public void leftButtonClick(View view)
    {
        if (buttonValues.get(0) == 0)
        {
           winner();
        }

        else
        {
            loser();
        }
    }

    public void rightButtonClick(View view)
    {
        if (buttonValues.get(1) == 0)
        {
            winner();
        }

        else
        {
            loser();
        }
    }

    public void winner()
    {
        Intent oldintent = getIntent();
        Bundle oldbundle = oldintent.getExtras();
        int gambleamount = oldintent.getIntExtra("GAMBLE", 1);
        int coins = oldintent.getIntExtra("COINS", 1);
        ArrayList<Integer> coinHistory = oldbundle.getIntegerArrayList("COIN_HISTORY");

        Intent intent = new Intent(this, MainActivity.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinHistory);
        intent.putExtra("WINNER", true);
        intent.putExtra("GAMBLE", gambleamount);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void loser()
    {
        Intent oldintent = getIntent();
        Bundle oldbundle = oldintent.getExtras();
        int gambleamount = oldintent.getIntExtra("GAMBLE", 1);
        int coins = oldintent.getIntExtra("COINS", 1);
        ArrayList<Integer> coinHistory = oldbundle.getIntegerArrayList("COIN_HISTORY");

        Intent intent = new Intent(this, MainActivity.class);
        Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("COIN_HISTORY", coinHistory);
        intent.putExtra("WINNER", false);
        intent.putExtra("GAMBLE", gambleamount);
        intent.putExtra("COINS", coins);
        intent.putExtras(bundle);
        startActivity(intent);
    }
}

I appreciate any help anyone may be able to provide. 我感谢任何人都能提供的任何帮助。

Luke 卢克

UPDATE: Here's my logcat...or at least what I believe is the relevant portion. 更新:这是我的logcat ......或者至少我认为是相关部分。 I grabbed the text it gave me once the crash happened. 一旦碰撞发生,我抓住了它给我的文字。

04-06 16:10:39.091 3897-3897/? I/art: Late-enabling -Xcheck:jni
04-06 16:10:39.322 3897-3897/com.example.getcoins W/System: ClassLoader referenced unknown path: /data/app/com.example.getcoins-1/lib/arm64
04-06 16:10:39.363 3897-3897/com.example.getcoins I/InstantRun: Starting Instant Run Server for com.example.getcoins
04-06 16:10:42.158 3897-3897/com.example.getcoins W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-06 16:10:42.643 3897-3897/com.example.getcoins D/AndroidRuntime: Shutting down VM
04-06 16:10:42.645 3897-3897/com.example.getcoins E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.example.getcoins, PID: 3897
                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.getcoins/com.example.getcoins.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2671)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2736)
                                                                        at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6154)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null object reference
                                                                        at com.example.getcoins.MainActivity.onCreate(MainActivity.java:50)
                                                                        at android.app.Activity.performCreate(Activity.java:6683)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2624)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2736) 
                                                                        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6154) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 

UPDATE: 更新:

First off, thank you for your responses! 首先,谢谢你的回复! This has been very educational for me! 这对我来说非常有教育意义! I'd like to run by my current logic of what I think is going on to see if I'm on the right track. 我想按照我现在的逻辑运行,看看我是否走在正确的轨道上。 It seems like when the app is first compiled onto my phone, everything is okay (ie the global variables in main activity are seen and dealt with correctly). 看起来当应用程序首次编译到我的手机上时,一切正常(即主要活动中的全局变量被正确看到并处理)。

However, after looking at the link Pavel B. suggested I look at, it seems that through this process... A simplified illustration of the activity lifecycle. 然而,在看了Pavel B.建议的链接之后,看来,通过这个过程......似乎是活动生命周期的简化说明。

...once I kill the app and open it back up, it goes straight to the onCreate() method (and seems to have skipped the global variables defined above it). ...一旦我杀了应用程序并将其打开,它就会直接进入onCreate()方法(似乎已经跳过了上面定义的全局变量)。 Is this what is going on? 这是怎么回事?

I have voted up comments I have found helpful but it says since my reputation is less than 15 it won't be public. 我已经发表评论,我发现有帮助,但它说,因为我的声誉不到15,所以不会公开。

Thank you again SO much!! 再次感谢你!

Luke 卢克

this may or may not solve your issue, but when you call your 'gamble' activity from your main activity, you should be using startActivityForResult() and register a callback receiver to handle the result... 这可能会或可能不会解决您的问题,但是当您从主活动中调用“赌博”活动时,您应该使用startActivityForResult()并注册一个回调接收器来处理结果......

ie you're currently 'starting' your main activity over itself instead of just passing results back to it via setResult 即你现在正在“开始”你自己的主要活动,而不是仅仅通过setResult将结果传回给它

see: 看到:

https://developer.android.com/training/basics/intents/result.html https://developer.android.com/training/basics/intents/result.html

and

https://developer.android.com/reference/android/os/ResultReceiver.html https://developer.android.com/reference/android/os/ResultReceiver.html

UPDATE: 更新:

consider creating a static final request code you can use: 考虑创建一个可以使用的静态最终请求代码:

public static final int REQUEST_CODE_GAMBLE = 172;

change your getCoin methods to startActivityForResult(), using your static request code: 使用静态请求代码将getCoin方法更改为startActivityForResult():

public void getOneCoin(View view){
    Intent intent = new Intent(this, gamble.class);
    Bundle bundle = new Bundle();
    bundle.putIntegerArrayList("COIN_HISTORY", coinsOverTime);
    intent.putExtra("GAMBLE", 1);
    intent.putExtra("COINS", coins);
    intent.putExtras(bundle);
    startActivityForResult(intent, REQUEST_CODE_GAMBLE);
}

then override onActivityResult() in your MainActivity: 然后覆盖MainActivity中的onActivityResult():

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
    if(requestCode == REQUEST_CODE_GAMBLE){
        if(resultCode == RESULT_OK){

            //do all that same stuff you were doing in onCreate() in your MainActivity
            //i.e. :
            coins = intent.getIntExtra("COINS", 1);
            //etc

        }
    }


}

then in your winner() and loser() methods in the gamble activity, simply set the result and call finish(): 然后在赌博活动的wins()和loser()方法中,只需设置结果并调用finish():

public void winner()
{
    Intent oldintent = getIntent();
    Bundle oldbundle = oldintent.getExtras();
    int gambleamount = oldintent.getIntExtra("GAMBLE", 1);
    int coins = oldintent.getIntExtra("COINS", 1);
    ArrayList<Integer> coinHistory = oldbundle.getIntegerArrayList("COIN_HISTORY");
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    bundle.putIntegerArrayList("COIN_HISTORY", coinHistory);
    intent.putExtra("WINNER", true);
    intent.putExtra("GAMBLE", gambleamount);
    intent.putExtra("COINS", coins);
    intent.putExtras(bundle);
    getParent().setResult(Activity.RESULT_OK, intent);
    finish();
}

When your gamble activity "finishes", it will send all that intent data to your MainActivity's new onActivityResult() method, and you can do with it what you'd like there 当您的赌博活动“完成”时,它会将所有意图数据发送到您的MainActivity的新onActivityResult()方法,并且您可以在其中执行您想要的操作

It seems that the error is that Your coinsOverTime array is null. 似乎错误是您的coinsOverTime数组为空。 It works fine when Your activity is started with an intent in which this array is stored as an extra, but this is not the case when your app is going off screen and returning. 当您的活动以一个意图启动时,它可以正常工作,其中此数组作为额外存储,但当您的应用程序离开屏幕并返回时,情况并非如此。

When You are pressing home, Your activity should save its state and restore it as it comes back on screen. 当您按下主页时,您的活动应该保存其状态并在屏幕上显示时将其恢复。 Pls read Saving and restoring activity state section here: https://developer.android.com/guide/components/activities/activity-lifecycle.html 请阅读保存和恢复活动状态部分: https//developer.android.com/guide/components/activities/activity-lifecycle.html

Just put if(coinsOverTime != null) before coinsOverTime.add(coins); 只需将if(coinsOverTime != null) coinsOverTime.add(coins);之前coinsOverTime.add(coins); every where. 每个地方。 This crash happens because the coinsOverTime array is Null pointer when your activity be resumed. 发生此崩溃是因为当您的活动恢复时, coinsOverTime数组是Null指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM