2016-10-05 1 views
0

프로젝트를 실행할 때 메시지 콘솔에 오류가 없지만 충돌은 계속 발생합니다. 나는 이유를 발견 할 수 없었다. 내가 묻는 유사한 질문 중 일부를 거치려고했지만 주어진 솔루션을 구현했지만 여전히 도움이되지 못했습니다. 여기 내 코드가있다. 이건 내 활동 XML입니다단순한 ListView 프로젝트가 충돌하지만 오류는 표시되지 않습니다.

package com.example.omar.quakereport; 

public class Earthquakes { 
    private String mMagnitude; 
    private String mLocation; 
    private String mDate; 

    public Earthquakes(String magnitude, String location, String date){ 
     mMagnitude = magnitude; 
     mLocation = location; 
     mDate = date; 
    } 

    public String getMagnitude(){ 
     return mMagnitude; 
    } 

    public String getLocation(){ 
     return mLocation; 
    } 

    public String getDate(){ 
     return mDate; 
    } 

:

package com.example.omar.quakereport; 


import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

import java.util.ArrayList; 

public class EarthquakeActivity extends AppCompatActivity { 
    ListView earthquakeListView; 
    ArrayList<String> earthquakes; 
    ArrayAdapter<String> adapter; 

// public static final String LOG_TAG = EarthquakeActivity.class.getName(); 

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

     // Create a fake list of earthquake locations. 
     earthquakes = new ArrayList<>(); 
     earthquakes.add("San Francisco"); 
     earthquakes.add("London"); 
     earthquakes.add("Tokyo"); 
     earthquakes.add("Mexico City"); 
     earthquakes.add("Moscow"); 
     earthquakes.add("Rio de Janeiro"); 
     earthquakes.add("Paris"); 

     // Find a reference to the {@link ListView} in the layout 
     earthquakeListView = (ListView) findViewById(R.id.list); 

     // Create a new {@link ArrayAdapter} of earthquakes 
     adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, earthquakes); 

     // Set the adapter on the {@link ListView} 
     // so the list can be populated in the user interface 
     earthquakeListView.setAdapter(adapter); 
    } 
} 

내 게터를 수용하는 클래스입니다

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

그리고 이것은 내 목록 항목 XML입니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

</LinearLayout> 
+1

봐, 드롭 다운 메뉴에서 선택되어 있는지 "자세한 정보"를 확인하고 아무것도 검색 (즉, 어떤 필터)이 없도록하기 드롭 바로 오른쪽에있는 상자 하위. 앱에 충돌이 발생하면 거기에 뭔가가 있어야합니다. –

+0

이것은 Udacity 과정 출신입니다. 나는 지진이 arraylist에서 지진 수업으로 옮겨지는 시점에 이르지 않았다고 가정합니까? 우리는 당신이 어떤 오류를 겪고 있는지 알아야합니다. – ShadowGod

답변

0

ListViews 방향이 없습니다. 속성.

당신은 당신이 사용할 필요가, 그 다음 상대/선형/프레임 레이아웃

에 ListView에 포장해야 ArrayAdapter<Earthquake> adapter; (see here) (당신의 클래스 이름은 단수 수 있도록). 또는 ArrayAdapter<String>이 데이터를 표시하는 데 사용하는대로 Earthquake 클래스에 toString()을 구현해야합니다.

, 그때 편집 표시 TextViews 및 지진 데이터를 추가 할 항목 레이아웃, 그리고 마지막으로 사용 지진 항목 XML 레이아웃,하지 android.R.layout.simple_list_item_1

해당 어댑터가 있으면, 당신은 실제로이 작업을 수행 할 수 있습니다 추가 데이터를 표시 안드로이드 스튜디오의 하단에있는 "안드로이드 모니터"탭에서

adapter.add(new Earthquake("magnitude", "location", "date")); 
+0

아직 스택 추적을 제공하지 않았기 때문에 충돌 문제를 해결하지 못합니다. –

+0

사실, null이나 다른 명백한 실수가 될 수있는 사항이 없기 때문에 문제가 충분히 해결됩니다. –

관련 문제