2017-11-04 4 views
-3

numbersIntent 청취자를 클릭하여 내 NumbersActivity 클래스 파일을 열면 내 Android 앱이 다운됩니다.onclick에서 앱이 다운 됨

나는 문자열을 while 루프를 사용하여 할당하려면 NumbersActivity 클래스 파일에 설정된 arraylist 이름 "단어"를 사용하고 있습니다.

NumbersActivity 클래스 파일을 제외한 다른 클래스는 괜찮아 보입니다. 나는 이유를 알 수 없다. 아무도 도와 줄 수 있니? 여기

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 파일입니다 : 아래
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 자바 파일 : 아래

다음은
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); 
      } 
     }); 
    }  
} 

내 로그 캣의 결과 인 자바 파일입니다

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/tan_background" 
    android:orientation="vertical" 
    tools:context="com.example.android.miwok.MainActivity"> 

    <TextView 
     android:id="@+id/numbers" 
     style="@style/CategoryStyle" 
     android:background="@color/category_numbers" 
     android:text="@string/category_numbers" /> 

    <TextView 
     android:id="@+id/family" 
     style="@style/CategoryStyle" 
     android:background="@color/category_family" 
     android:text="@string/category_family" /> 

    <TextView 
     android:id="@+id/colors" 
     style="@style/CategoryStyle" 
     android:background="@color/category_colors" 
     android:text="@string/category_colors" /> 

    <TextView 
     android:id="@+id/phrases" 
     style="@style/CategoryStyle" 
     android:background="@color/category_phrases" 
     android:text="@string/category_phrases" /> 

</LinearLayout> 



here is my activity_numbers xml file 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    android:id="@+id/rootView" 
    tools:context="com.example.android.miwok.NumbersActivity"> 

</LinearLayout> 
+0

포스트 로그 캣 오류 –

답변

1

당신이 코드 행 다음에있다 : 것을 제거

while (index < words.size()); 

시도 ";" 운영자의 말에은 다음과 같이해야한다 : 동일 또는 해당 ID를 가진 다른 레이아웃에보기가 아니라면

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

감사합니다 지금 일하고있다! –

-1

편집 대답하여 NumbersActivity에서

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 활동을 여는 동안 앱이 다운됩니다. 내가 아는 한, 자바 코드에는 실수가 없다. 숫자에 몇 가지 오류가있을 수 있습니다. XML –