android中未定义的构造函数

时间:2014-12-05 04:57:27

标签: java android constructor fragment undefined

我正在创建一个处理片段的应用程序,并且我一直为构造函数收到一个未定义的错误。

`

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);

我收到的错误是&#34;构造函数ClientFragment.ScrapAdapter(Scrap)未定义&#34;

3 个答案:

答案 0 :(得分:0)

您的构造函数接受ArrayList<Scrap>作为参数

public ScrapAdapter(ArrayList<Scrap> scraps)

但是你要将Scrap对象传递给它

ScrapAdapter adapter = new ScrapAdapter(mScraps);

答案 1 :(得分:0)

将Scrap的ArrayList传递给ScrapAdapter:

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

或者将ScrapAdapter构造函数参数ArrayList更改为Scrap:

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

答案 2 :(得分:0)

您的构造函数需要ArrayList

public ScrapAdapter(ArrayList<Scrap> scraps)

但您传递的是Object,而不是ArrayList的{​​{1}}:

Object

您可能需要做的是创建private Scrap mScraps; ScrapAdapter adapter = new ScrapAdapter(mScraps); ArrayList并传递它。或者,您可能希望更改构造函数的参数以接收Scrap而不是Scrap