2014-10-28 3 views
0

Android 프로그래밍으로 시작합니다. 여기 ArrayAdapter() : 적절한 생성자가 없습니다.

public class StationListAdapter extends ArrayAdapter<Station> { 

    private ArrayList<Station> stations; 
    private Context context; 
    private int resource; 
    LayoutInflater layoutInflater; 

    //Constructor - args : (context, resourceId, ArrayList<MyClass>) 
    public StationListAdapter(Context context, int resource, ArrayList<Station> stations) { 

     this.context = context; 
     this.resource = resource; 
     this.stations = stations; 
     layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 

가 frament 예 어댑터의 일부입니다 :

다음

Error: no suitable constructor found for ArrayAdapter()

내 personnal 어댑터입니다 : 나는 다음과 같은 오류가 나는 내 프로그램을 컴파일 할 수 없습니다

public void onArrayListReady(ArrayList<Station> stations) { 
    TextView textView = (TextView) this.view.findViewById(R.id.fragment_list_textview); 
    ListView listView = (ListView) this.view.findViewById(R.id.fragment_list_stations_list); 
    adapter = new StationListAdapter(getActivity(), R.layout.fragment_list_row, stations); 
    listView.setAdapter(adapter); 
} 
+1

당신은 어댑터에서'super'를 호출하지 않습니다 – Achrome

+0

도움을 주셔서 대단히 감사합니다. – valvince

답변

1

어댑터를 올바르게 초기화하려면 생성자에서 슈퍼 생성자를 호출해야합니다.

+0

대단히 고마워! 그거였다. 어리석은 질문처럼 들릴지 모르겠지만 어떻게하면 구조를 만들고 부모 생성자를 호출해야한다는 것을 알 수 있습니까? (Java 및 Android의 초보자) – valvince

+0

바보 같은 질문은 외면되지 않은 질문입니다. 확장중인 클래스도 초기화해야한다고 가정해야합니다. 따라서 수퍼 생성자 호출을 의도적으로 방지하지 않는 한 항상 슈퍼 생성자를 호출하는 것이 좋습니다. –

+0

그건, 나는 fotget하지 않습니다. 다시 한번 감사드립니다. – valvince

관련 문제