2017-11-04 11 views
-3

numbersIntentリスナーをクリックしてNumbersActivityクラスファイルを開くと、アンドロイドアプリがクラッシュするオンクラック時にアプリがクラッシュする

NumbersActivityクラスファイルに設定されたアライリスト名 "word"を使用して、whileループを使用している文字列のリストを割り当てています。

NumbersActivityクラスファイルを除いて、他のクラスはうまく見えます。私は理由を理解することができません、誰も助けることができますか?

以下

javaファイルの下

package com.example.android.miwok; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.TextView; 
import android.widget.Button; 
import android.view.View.OnClickListener; 

import static android.R.attr.onClick; 

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Set the content of the activity to use the activity_main.xml layout file 
     setContentView(R.layout.activity_main); 

// public void openNumbersList(View view){ 
//  Intent i = new Intent(this,NumbersActivity.class); 
//  startActivity(i); 
// } 

     // Find the View that shows the numbers category 
     TextView numbers = (TextView) findViewById(R.id.numbers); 

     // Set a click listener on that View 
     numbers.setOnClickListener(new OnClickListener() { 
      // The code in this method will be executed when the numbers category is clicked on. 
      @Override 
      public void onClick(View view) { 
       // Create a new intent to open the {@link NumbersActivity} 
       Intent numbersIntent = new Intent(MainActivity.this, NumbersActivity.class); 

       // Start the new activity 
       startActivity(numbersIntent); 
      } 
     }); 

     // Find the View that shows the family category 
     TextView family = (TextView) findViewById(R.id.family); 

     // Set a click listener on that View 
     family.setOnClickListener(new OnClickListener() { 
      // The code in this method will be executed when the family category is clicked on. 
      @Override 
      public void onClick(View view) { 
       // Create a new intent to open the {@link FamilyActivity} 
       Intent familyIntent = new Intent(MainActivity.this, FamilyActivity.class); 

       // Start the new activity 
       startActivity(familyIntent); 
      } 
     }); 

     // Find the View that shows the colors category 
     TextView colors = (TextView) findViewById(R.id.colors); 

     // Set a click listener on that View 
     colors.setOnClickListener(new OnClickListener() { 
      // The code in this method will be executed when the colors category is clicked on. 
      @Override 
      public void onClick(View view) { 
       // Create a new intent to open the {@link ColorsActivity} 
       Intent colorsIntent = new Intent(MainActivity.this, ColorsActivity.class); 

       // Start the new activity 
       startActivity(colorsIntent); 
      } 
     }); 

     // Find the View that shows the phrases category 
     TextView phrases = (TextView) findViewById(R.id.phrases); 

     // Set a click listener on that View 
     phrases.setOnClickListener(new OnClickListener() { 
      // The code in this method will be executed when the phrases category is clicked on. 
      @Override 
      public void onClick(View view) { 
       // Create a new intent to open the {@link PhrasesActivity} 
       Intent phrasesIntent = new Intent(MainActivity.this, PhrasesActivity.class); 

       // Start the new activity 
       startActivity(phrasesIntent); 
      } 
     }); 
    }  
} 

は私のlogcat結果です:

以下
11-01 23:12:59.226 23384-23384/? E/Zygote: v2 
11-01 23:12:59.226 23384-23384/? I/libpersona: KNOX_SDCARD checking this for 10238 
11-01 23:12:59.226 23384-23384/? I/libpersona: KNOX_SDCARD not a persona 
11-01 23:12:59.226 23384-23384/? I/SELinux: Function: selinux_compare_spd_ram, index[1], SPD-policy is existed. and_ver=SEPF_SM-A700FD_5.0.2-1 ver=51 
11-01 23:12:59.226 23384-23384/? W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [2], priority version is VE=SEPF_SECMOBILE_6.0.1_0029 
11-01 23:12:59.226 23384-23384/? W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=com.example.android.miwok 
11-01 23:12:59.226 23384-23384/? I/art: Late-enabling -Xcheck:jni 
11-01 23:12:59.286 23384-23384/? D/TimaKeyStoreProvider: TimaSignature is unavailable 
11-01 23:12:59.286 23384-23384/? D/ActivityThread: Added TimaKeyStore provider 
11-01 23:12:59.456 23384-23384/com.example.android.miwok W/System: ClassLoader referenced unknown path: /data/app/com.example.android.miwok-1/lib/arm 
11-01 23:12:59.856 23384-23384/com.example.android.miwok D/SecWifiDisplayUtil: Metadata value : none 
11-01 23:12:59.856 23384-23384/com.example.android.miwok D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{cca8e96 I.E...... R.....ID 0,0-0,0} 
11-01 23:12:59.866 23384-23399/com.example.android.miwok D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
11-01 23:12:59.946 23384-23399/com.example.android.miwok I/Adreno: QUALCOMM build     : d842ad3, Ia10634f51b 
                    Build Date      : 01/04/16 
                    OpenGL ES Shader Compiler Version: XE031.06.00.05 
                    Local Branch      : 
                    Remote Branch     : quic/LA.BR.1.2.6_rb1.7 
                    Remote Branch     : NONE 
                    Reconstruct Branch    : NOTHING 
11-01 23:12:59.956 23384-23399/com.example.android.miwok I/OpenGLRenderer: Initialized EGL, version 1.4 
11-01 23:12:59.986 23384-23384/com.example.android.miwok V/ActivityThread: updateVisibility : ActivityRecord{ee55121 [email protected] {com.example.android.miwok/com.example.android.miwok.MainActivity}} show : true 
11-01 23:13:00.006 23384-23384/com.example.android.miwok D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1 
11-01 23:13:00.026 23384-23399/com.example.android.miwok D/libGLESv1: DTS_GLAPI : DTS is not allowed for Package : com.example.android.miwok 
11-01 23:13:00.076 23384-23384/com.example.android.miwok I/Timeline: Timeline: Activity_idle id: [email protected] time:230587661 
11-01 23:13:02.196 23384-23384/com.example.android.miwok D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1 
11-01 23:13:02.236 23384-23384/com.example.android.miwok I/Timeline: Timeline: Activity_idle id: [email protected] time:230589825 
11-01 23:13:03.176 23384-23384/com.example.android.miwok I/Timeline: Timeline: Activity_idle id: [email protected] time:230590768 
11-01 23:13:09.576 23384-23384/com.example.android.miwok D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
11-01 23:13:09.616 23384-23384/com.example.android.miwok D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
11-01 23:13:09.626 23384-23384/com.example.android.miwok I/Timeline: Timeline: Activity_launch_request id:com.example.android.miwok time:230597210 

は私のNumbersActivity Javaファイルである:ここで

package com.example.android.miwok; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 

import android.widget.LinearLayout; 
import android.widget.TextView; 

import java.util.ArrayList; 

public class NumbersActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_numbers); 

     ArrayList<String> words = new ArrayList<String>(); 
     words.add("One"); 
     words.add("Two"); 
     words.add("three"); 
     words.add("Four"); 
     words.add("Five"); 
     words.add("Six"); 
     words.add("Seven"); 
     words.add("Eight"); 
     words.add("Nine"); 
     words.add("Ten"); 

     LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView); 
     int index = 0; 
      while (index < words.size()); 
     { 

      TextView wordView = new TextView(this); 
      wordView.setText(words.get(index)); 
      rootView.addView(wordView); 
index++; 

     } 

    } 

} 

は、私の活動のメインXMLファイルです

あなたのNumbersActivityで
+0

ポストlogcatエラー –

答えて

1

あなたは、コードの行を次のようしている。

while (index < words.size()); 

ことを削除するようにしてください ";"オペレータの終了時に、次のようにすべきである:同じまたはそのIDを持つ異なるレイアウトのビューがありますがない限り

while (index < words.size()) 
+0

を取る! –

-1

編集回答

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     View view = getLayoutInflater().inflate(R.layout.activity_numbers, null); 
     setContentView(view); 

     ArrayList<String> words = new ArrayList<String>(); 
     words.add("One"); 
     words.add("Two"); 
     words.add("three"); 
     words.add("Four"); 
     words.add("Five"); 
     words.add("Six"); 
     words.add("Seven"); 
     words.add("Eight"); 
     words.add("Nine"); 
     words.add("Ten"); 

     int index = 0; 
     while (index < words.size());{ 
      TextView wordView = new TextView(this); 
      wordView.setText(words.get(index)); 
      view.addView(wordView); 
      index++; 
     } 

    } 
+0

スペルミスは、不可能です。あなたが 'activity_numbers'という名前のレイアウトを持っている場合、' activity_number'を書くことは、それが存在しないことを知っているので、IDEにエラーを表示します(ブロックコンパイル)。レイアウトが存在する場合は意図したものとは異なるものが膨らみますが、存在しないビューを取得しようとしないとまだ実行されません – Zoe

+0

私のxmlファイルが既に追加されていますXML部分から? –

+0

これは主なXMLです。Numbersアクティビティを開いている間にアプリがクラッシュします。私が知る限り、JAVAコードには間違いがありません。数値に何らかのエラーがある可能性があります。 –

関連する問題