2016-11-26 11 views
0

「ゲーム」オブジェクトをFirebaseデータベースに入れるコードに取り組んでいます。各ゲームには名前と「プレイヤー」という名前のアーリーリストがあり、それぞれに名前と「ターゲット」があります。しかし、私はコードを実行すると、アプリケーションがクラッシュするだけで明確なエラーは、それだけでメソッドを実行することができないと述べています。私はそれがゲームの名前だけで動作するようになる以前に、プレイヤーのリストと関係があると確信しています。Firebaseにオブジェクトのリストを追加する

Games: 
    Game1: 
     name: Johns Game 
     Players: 
      John 
      Mike 

    Game2:...... 

EDIT 1 プレイヤーがプレイヤー名を尋ねるダイアログで初期化し、その後にプレイヤーを渡している:私のような組織化私のデータベースをしたい明確にすることが

public void beginGame(View view) { 
    mDatabase = FirebaseDatabase.getInstance().getReference(); 


    EditText gameNameField = (EditText) findViewById(R.id.gameName); 
    String gameName = gameNameField.getText().toString().trim(); 
    Collections.shuffle(players); 
    if (gameName.isEmpty()) { 
     int duration = Toast.LENGTH_LONG; 

     Toast toast = Toast.makeText(getApplicationContext(), 
       R.string.toast_no_game_name, duration); 
     toast.show(); 

    } else if (playerNames.size() < 2) { 
     int duration = Toast.LENGTH_LONG; 

     Toast toast = Toast.makeText(getApplicationContext(), 
       R.string.toast_not_enough_players, duration); 
     toast.show(); 

    } else { 
     for (int i = 0; i < players.size(); i++) { 
      if (i != (players.size() - 1)) { 
       players.get(i).target = players.get(i + 1); 
      } else { 
       players.get(i).target = players.get(0); 
      } 
     } 
     Game game = new Game(gameName, players); 
     mDatabase.child("Games").child(gameName).setValue(game); 

     Intent intent = new Intent(StartNewGameActivity.this, SessionsActivity.class); 
     startActivity(intent); 
    } 
} 

配列リスト

public void addNewPlayer(View view) { 
    DialogFragment newFragment = new CreatePlayerDialogFragment(); 
    newFragment.show(getSupportFragmentManager(), "Player"); 
} 

@Override 
public void onDialogPositiveClick(String name) { 
    playerNames.add(name); 
    players.add(new Player(name)); 
} 

そして、ここで私のLogcat

11-26 12:15:29.780 10730-10730/com.example.hunte.assassin E/AndroidRuntime: FATAL EXCEPTION: main 
    Process: com.example.hunte.assassin, PID: 10730 
    java.lang.IllegalStateException: Could not execute method for android:onClick 
     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) 
     at android.view.View.performClick(View.java:5217) 
     at android.view.View$PerformClick.run(View.java:21342) 
     at android.os.Handler.handleCallback(Handler.java:739) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:148) 
     at android.app.ActivityThread.main(ActivityThread.java:5551) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
    Caused by: java.lang.reflect.InvocationTargetException 
     at java.lang.reflect.Method.invoke(Native Method) 
     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
     at android.view.View.performClick(View.java:5217)  
     at android.view.View$PerformClick.run(View.java:21342)  
     at android.os.Handler.handleCallback(Handler.java:739)  
     at android.os.Handler.dispatchMessage(Handler.java:95)  
     at android.os.Looper.loop(Looper.java:148)  
     at android.app.ActivityThread.main(ActivityThread.java:5551)  
     at java.lang.reflect.Method.invoke(Native Method)  
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)  
    Caused by: java.lang.StackOverflowError: stack size 8MB 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
     at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
     at com.google.android.gms.internal.zzbq 
11-26 12:15:29.780 10730-10740/com.example.hunte.assassin I/art: Background sticky concurrent mark sweep GC freed 6950(796KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 136MB/136MB, paused 42.643ms total 65.881ms 
11-26 12:15:30.129 1761-1821/? V/WindowOrientationListener: Proposed rotation changed! : currentRotation=0, proposedRotation=0, oldProposedRotation=-1, predictedRotation=0, timeDeltaMS=66.65039, isAccelerating=false, isFlat=false, isSwinging=false, isOverhead=false, isTouched=false, timeUntilSettledMS=0.0, timeUntilAccelerationDelayExpiredMS=0.0, timeUntilFlatDelayExpiredMS=0.0, timeUntilSwingDelayExpiredMS=0.0, timeUntilTouchDelayExpiredMS=0.0 
11-26 12:15:30.188 1761-2477/? D/sensors_hal_LGMotionAccel: processInd: LP2: X: 1.027176 Y: 4.640945 Z: 8.011398 SAM TS: 153411799 HAL TS:135753777272948 elapsedRealtimeNano:135753856670678 
11-26 12:15:30.311 10730-10730/com.example.hunte.assassin D/Error: ERR: exClass=java.lang.StackOverflowError 
11-26 12:15:30.311 10730-10730/com.example.hunte.assassin D/Error: ERR: exMsg=stack size 8MB 
11-26 12:15:30.311 10730-10730/com.example.hunte.assassin D/Error: ERR: file=Method.java 
11-26 12:15:30.311 10730-10730/com.example.hunte.assassin D/Error: ERR: class=java.lang.reflect.Method 
11-26 12:15:30.311 10730-10730/com.example.hunte.assassin D/Error: ERR: method=invoke line=-2 
11-26 12:15:30.381 10730-10730/com.example.hunte.assassin D/Error: ERR: stack=java.lang.IllegalStateException: Could not execute method for android:onClick 
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) 
    at android.view.View.performClick(View.java:5217) 
    at android.view.View$PerformClick.run(View.java:21342) 
    at android.os.Handler.handleCallback(Handler.java:739) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5551) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: java.lang.reflect.InvocationTargetException 
    at java.lang.reflect.Method.invoke(Native Method) 
    at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
    at android.view.View.performClick(View.java:5217)  
    at android.view.View$PerformClick.run(View.java:21342)  
    at android.os.Handler.handleCallback(Handler.java:739)  
    at android.os.Handler.dispatchMessage(Handler.java:95)  
    at android.os.Looper.loop(Looper.java:148)  
    at android.app.ActivityThread.main(ActivityThread.java:5551)  
    at java.lang.reflect.Method.invoke(Native Method)  
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)  
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)  
Caused by: java.lang.StackOverflowError: stack size 8MB 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) 
    at com.google.android.gms.internal.zzbqi.zzaE(Unknown Source) 
    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) 
at com.google.android.gms.internal.zzbqi 
11-26 12:15:30.383 10730-10730/? D/Error: ERR: TOTAL BYTES WRITTEN: 20167208 
11-26 12:15:30.383 10730-10730/? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 20167300) 
11-26 12:15:30.383 10730-10730/? E/AndroidRuntime: Error reporting crash 
android.os.TransactionTooLargeException: data parcel size 20167300 bytes 
at android.os.BinderProxy.transactNative(Native Method) 
at android.os.BinderProxy.transact(Binder.java:503) 
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4547) 
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90) 
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) 
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) 
+0

で同様の疑問を持っていますプレーヤーはどこで初期化されますか?また、あなたのLogcatにも正確にありますか? – rhari

+0

@rhari編集はメインポストで行われました –

答えて

0

だから私は、正確なプレーヤーのコンストラクタを持っていませんでし(それが実際の名前に取るdidntの)が、場合には、私のコードを掲示イムは、あなたが部分を投稿することができ、将来の

public void beginGame(View view) { 
    final FirebaseDatabase database = FirebaseDatabase.getInstance(); 
    DatabaseReference ref = database.getReference(); 

    EditText gameNameField = (EditText) findViewById(R.id.gameName); 
    String gameName = gameNameField.getText().toString().trim(); 
    Collections.shuffle(players); 
    if (gameName.isEmpty()) { 
     int duration = Toast.LENGTH_LONG; 

     Toast toast = Toast.makeText(getApplicationContext(), 
       R.string.toast_no_game_name, duration); 
     toast.show(); 

    } else if (playerNames.size() < 2) { 
     int duration = Toast.LENGTH_LONG; 

     Toast toast = Toast.makeText(getApplicationContext(), 
       R.string.toast_not_enough_players, duration); 
     toast.show(); 

    } else { 
     for (int i = 0; i < players.size(); i++) { 
      if (i != (players.size() - 1)) { 
       players.get(i).target = players.get(i + 1); 
      } else { 
       players.get(i).target = players.get(0); 
      } 
     } 
     Game game = new Game(gameName, players); 
     DatabaseReference gamesRef = ref.child("Games").child(gameName).child("players"); 
     Map<String, Player> gamePlayers = new HashMap<>(); 
     for(int i = 0; i < players.size(); i++){ 
      Player currentPlayer = players.get(i); 
      gamesRef.child(currentPlayer.getName()).setValue(currentPlayer); 

     } 

    } 
} 
0

からのエラーは私の知る限りでは、あなたは一人の子供の下で多くの値を持つことはできませんされています。新しいプレーヤーごとに新しい子を作成するたびに、値を1つずつ設定してみてください。 mDatabase.child( "Games")。子(gameName).child(playerName); playerNameが変更され(i ++は配列リスト内でインクリメントされます)、新しい子が各項目に対して作成されます。結局のところとして