2017-04-06 13 views
1

私はAndroidスタジオの新人ではなく、一般的なプログラミングには初めてです(私は趣味として過去1年ほどのことをゆっくりと教えてきました)。Androidアプリのクラッシュが再開されたとき

多くの人が同様の質問をしていることは分かっていますが、それを解決するのに十分な解決策は理解できていないようです私の特別な問題。コンパイルすると、私のアプリはうまく動作し、私はそれが "正しく"(ツールバーの小さなものを除いて、それは後のhahaになる)すべてのことをやります。

私はそれを閉じた後、正しく開かれていません。ホーム画面に戻ってアプリに戻ることができますが、アプリを一度閉じてからもう一度開こうとすると、「停止しています」というメッセージが表示されます。

今、あなたに私のコード(このアプリケーションでは2つのアクティビティしかありません)と私の "logcat"を渡すと便利だと思います。しかし、私は現在、読んで、最初の場所で "logcat"を検索する方法を理解しようとしていますので、うまくいけばすぐにここでそれを持っていきます。

私の読んだところ、自分の問題は、私が宣言しているグローバル変数か、ボタンを動的に作るときにボタンIDを持つものであるということです。私は "スレッド"で問題を抱えている人に遭遇しますが、私はそれを私の特定のポジションに接続することに問題があります。しかし、これらの問題のいずれかが問題になっている場合は、問題の実際の内容を理解するのが苦労しています。私は誰にも提供することができるかもしれない任意の助けに感謝ここで

は私の主な活動...

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; 
    } 
} 

だと、ここでそれが話すギャンブルの活動です...

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); 
    } 
} 

ルーク

UPDATE:ここでは私のlogcatだ...あるいは、少なくとも私は信じている、関連する部分です。私はクラッシュが起こったときに私に与えたテキストをつかんだ。

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:

まず第一に、ご回答ありがとうございました!これは私にとって非常に教育的でした!私が正しい道を歩んでいるかどうかを確かめるための私の現在の論理で動かしたいと思います。アプリが最初に携帯電話にコンパイルされたときのように、すべての操作は正常です(メインアクティビティのグローバル変数が正しく表示され、正しく処理されているなど)。

ただし、リンクを見た後パベルB.私がアプリを殺すとバック​​アップ、それを開くと、このプロセスを経て... A simplified illustration of the activity lifecycle.

は...、それが行くようだ、私が見提案しましたonCreate()メソッドにまっすぐに(そして上で定義されたグローバル変数をスキップしたように見えます)。これは何が起こっているのですか?

私は参考にしたコメントを投票しましたが、私の評判は15未満で公開されないので、

もう一度ありがとうございます!

ルーク

+0

あなたの問題を解決する最も簡単な方法は、あなたのログ猫を共有することです。 –

+0

左の画面の下部にあるバーの_Android Monitor_をクリックすると、logcat – Sunshinator

+0

をご覧になれます。Sunshinatorに感謝の意を表します。私は上に投稿しました! –

答えて

0
これは、またはあなたの問題を解決しない場合があり

、しかし、あなたはあなたのメインの活動からあなたの "ギャンブルの活動を呼び出すとき、あなたはstartActivityForResultを(使用する必要があります)、その結果を処理するためのコールバックレシーバーを登録.. 。

https://developer.android.com/training/basics/intents/result.html:あなたは現在、自身の上にあなたの主な活動「を開始」だけではなくsetResult

参照を経由して、それに戻って結果を渡している。すなわち

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

UPDATE:

は、あなたが使用できるのstatic final要求コードを作成することを検討:

public static final int REQUEST_CODE_GAMBLE = 172; 

は(startActivityForResultにごgetCoin方法を変更)、あなたのstを使ってATIC要求コード:

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); 
} 

、あなたの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 

     } 
    } 


} 

)を単に設定ギャンブル活動の敗者()メソッド、結果とコールフィニッシュ():

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(); 
} 

あなたのギャンブルを有効にするとあなたのMainActivityの新しいonActivityResult()メソッドにそのすべてのインテントデータを送り、あなたはそれをあなたが望むものとすることができます

+0

この情報はありがとうございましたburadd!私はまだこの機能については聞いていないが、これは私の現在の問題の修正ではないが、それは私が関係なくやりたいことなので、ありがとう!上記のlogcatも追加しました。 –

+0

あなたが投票を検討するのに役立つなら、究極的にあなたの問題を解決するのを助けるなら、歓迎です。答えを受け入れることを検討してください。あなたのlogcatを見た後、あなたのクラッシュがあなたのarraylistがnullなのであなたのmainactivityが既に作成されていないので、意図から何も得られていないからです。このデータをonActivityResult()のコールバックレシーバーに入れると、おそらくこれが解決されます – buradd

+0

友人と話した後、アプリケーションを終了すると、何が起こるべきかを正しく宣言しました(アプリケーションが破壊されるように要求されたとき、私はarraylistをクリアする必要があると言いました)。 私が今主に関心を持っているのは、動かすのが嫌いですが、なぜ私のarraylistが再オープンしようとするとnullであるのかをよく理解しています。私の電話が何をしているのか分かりません。 –

0

あなたのcoinsOverTime配列がnullであると思われます。この配列が余分に格納されているインテントでアクティビティが開始されたときはうまく動作しますが、アプリが画面外に戻り、戻ってきたときはそうではありません。

あなたが自宅を押すと、あなたのアクティビティは状態を保存し、画面に戻って復元する必要があります。 Plsはの保存を読んで、ここでの活動状態セクション復元 : https://developer.android.com/guide/components/activities/activity-lifecycle.html

0

ことだけcoinsOverTime.add(coins);前にすべての場所をif(coinsOverTime != null)を置きます。このクラッシュは、アクティビティの再開時にcoinsOverTime配列がNULLポインタであるために発生します。

+0

これは彼の問題を解決することに近づくことさえできません、それはクラッシュを止めるでしょうが、彼は彼のarraylistのためのデータを持っていません..これは空のtry/catchを提案するのと同じです – buradd

+0

そうです。彼のAndroidプログラミングは初心者で、彼はちょうど彼のアプリでクラッシュの問題を防ぐためにしたい。 – Afshin

関連する問題