2014-12-05 2 views
0

Я делаю приложение, которое имеет дело с фрагментом, и я продолжаю получать неопределенную ошибку для конструктора.Undefined Constructor in android

`

public class ClientFragment extends Fragment { 
    private static final ClientFragment This = null; 
    final ClientFragment context = This; 
    private static String TAG = "This thing here"; 
    private static final String DIALOG_IMAGE = "image"; 
    private static final int REQUEST_PHOTO = 1; 
    static final String EXTRA_MEM_ID = "com.example.project2.memID"; 

    private Scrap mScraps; 
    Uri imageFileUri; 



    public static ClientFragment newInstance(UUID memID) { 
     Bundle args = new Bundle(); 
     args.putSerializable(EXTRA_MEM_ID, memID); 
     ClientFragment fragment = new ClientFragment(); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //this snags the UUID sent from MainActivity and tosses it to BookMarks 
     UUID memId = (UUID)getArguments().getSerializable(EXTRA_MEM_ID); 
     mScraps = BookMarks.get(getActivity()).getScraps(memId); 
} 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, 
    Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.fragment_scraps, parent, false); 





    final ListView mListView= (ListView)v.findViewById(R.id.listview); 
    ScrapAdapter adapter = new ScrapAdapter(mScraps); 

    mListView.setAdapter(adapter); //setListAdapter sets the adapter to a specific listview 

return v; 
} 


    private static final int TAKE_PICTURE_REQUEST = 0; 


    private class ScrapAdapter extends ArrayAdapter<Scrap> { 
     public ScrapAdapter(ArrayList<Scrap> scraps) { 
      super(getActivity(), 0, scraps); 
     } 
     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      // If we weren't given a view, inflate one 
      if (convertView == null) { 
       convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_memory, null); 
      } 
      // Configure the view 
      Scrap c = getItem(position); 
      //shows title 
      TextView titleTextView =(TextView)convertView.findViewById(R.id.list_item_titleTextView); 
      titleTextView.setText(c.getTitle()); 
      //shows date memory was made 
      TextView dateTextView =(TextView)convertView.findViewById(R.id.list_item_dateTextView); 
      dateTextView.setText(c.getDate().toString()); 
      return convertView; 
     } 
    }}` 

ошибка исходит от ScrapAdapter adapter = new ScrapAdapter(mScraps); конкретно new ScrapAdapter(mScraps);

Ошибка я получаю является "Конструктор ClientFragment.ScrapAdapter (лом) не определено"

+0

Вам необходимо передать ArrayList в конструктор Adapter, но вы передаете одиночный объект Scrap –

ответ

0

ваш конструктор принимает ArrayList<Scrap> в качестве аргумента

public ScrapAdapter(ArrayList<Scrap> scraps) 

но вы пропускание Scrap объекта к нему вместо

ScrapAdapter adapter = new ScrapAdapter(mScraps); 
0

Либо пройти ArrayList из лома ScrapAdapter:

ArrayList<Scrap> mScraps; 
ScrapAdapter adapter = new ScrapAdapter(mScraps); 

Или изменить ScrapAdapter параметра конструктора ArrayList в Ломе:

public ScrapAdapter(Scrap scraps) { 
    super(getActivity(), 0, scraps); 
} 
0

Вашему конструктору нужен ArrayList:

public ScrapAdapter(ArrayList<Scrap> scraps) 

Но вы пропускание Object, не ArrayList из Object:

private Scrap mScraps; 
ScrapAdapter adapter = new ScrapAdapter(mScraps); 

Может быть то, что вам нужно сделать, это создание ArrayList из Scrap и передать его. Или, может быть, вы хотите изменить свой конструктор, чтобы получить Scrap вместо ArrayList.