2014-12-05 137 views
0

我正在做一個應用程序,處理一個片段,我不斷收到一個構造函數未定義的錯誤。未定義的構造函數在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對象 – 2014-12-05 05:00:12

回答

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,而不是ArrayListObject的:

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

也許你需要做的是建立一個ScrapArrayList並將其傳遞了什麼。或者,也許,你想改變你的構造函數的參數來接收Scrap而不是ArrayList