Java Android-未找到合适的构造函数

Java Android-未找到合适的构造函数,java,android,android-intent,android-fragments,android-activity,Java,Android,Android Intent,Android Fragments,Android Activity,重建项目后,出现以下错误: 无法解析构造函数的意图(匿名android.widget.AdapterView.OnItemClickListener,java.lang.Class>) 有人知道错误的意思吗?构造函数有什么问题?我如何解决这个问题 public class FragmentWCLine extends android.support.v4.app.Fragment { public final static String EXTRA_MESSAGE = "Station

重建项目后,出现以下错误:

无法解析构造函数的意图(匿名android.widget.AdapterView.OnItemClickListener,java.lang.Class>)

有人知道错误的意思吗?构造函数有什么问题?我如何解决这个问题

public class FragmentWCLine extends android.support.v4.app.Fragment {

    public final static String EXTRA_MESSAGE = "Station_key";

    private class WC {
        private CharSequence station;
        private CharSequence zone;
        private Class<? extends Activity> activityClass;
        private Class<? extends android.support.v4.app.Fragment> fragmentClass;

        public WC(int stationResId, int zoneResId, Class<? extends Activity> activityClass, Class<? extends android.support.v4.app.Fragment> fragmentClass) {
            this.fragmentClass = fragmentClass;
            this.activityClass = activityClass;
            this.station = getResources().getString(stationResId);
            this.zone = getResources().getString(zoneResId);
        }

        @Override
        public String toString() { return station.toString(); }
        public String getzone(){ return zone.toString(); }
    }

    private static WC[] mWC;

    /**
     * Whether or not the activity is in two-pane mode, i.e. running on a tablet
     * device.
     */
    private boolean mTwoPane;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View v = inflater.inflate(R.layout.fragment_wc_line, container, false);

        // Instantiate the list of stations.
        mWC = new WC[]{
                new WC(R.string.bank, R.string.zone_1, WCBankActivity.class, FragmentWCBank.class),
                new WC(R.string.wat, R.string.zone_1, WCWATActivity.class, FragmentWCWAT.class)
        };

        final ListView listView = (ListView)v.findViewById(R.id.list_wc);
        listView.setAdapter(new MyAdapter(getActivity(), mWC));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(mTwoPane){

                    setItemNormal();
                    View rowView = view;
                    setItemSelected(rowView);
                }
                else{
                    Intent intent = new Intent(this, mWC[position].activityClass);

                    String station = mWC[position].station.toString();
                    intent.putExtra(EXTRA_MESSAGE, station);

                    startActivity(intent);
                }
            }

            public void setItemSelected(View view){
                View rowView = view;
                view.setBackgroundColor(Color.parseColor("#66CCCC"));

                TextView tv0 = (TextView)rowView.findViewById(R.id.list_item_station);
                tv0.setTextColor(Color.parseColor("#000099"));

                TextView tv1 = (TextView)rowView.findViewById(R.id.list_item_zone);
                tv1.setTextColor(Color.parseColor("#000099"));
            }

            public void setItemNormal()
            {
                for (int i=0; i< listView.getChildCount(); i++) {
                    View v = listView.getChildAt(i);
                    v.setBackgroundColor(Color.TRANSPARENT);

                    TextView tv0 = ((TextView) v.findViewById(R.id.list_item_station));
                    tv0.setTextColor(Color.WHITE);

                    TextView tv1 = ((TextView) v.findViewById(R.id.list_item_zone));
                    tv1.setTextColor(Color.parseColor("#B5B5B5"));
                }
            }
        });

        return v;
    }

    static class MyAdapter extends BaseAdapter {

        static class ViewHolder {
            TextView station;
            TextView zone;
        }

        LayoutInflater inflater;
        WC[] mWC;

        public MyAdapter(Context contexts, WC[] samples) {
            this.mWC = samples;
            inflater = LayoutInflater.from(contexts);
        }

        @Override
        public int getCount() {
            return mWC.length;
        }

        @Override
        public Object getItem(int position) {
            return mWC[position];
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        /**set selected position**/
        private int selectPosition = -1;
        public void setSelectPosition(int position){
            if(position!=selectPosition){
                selectPosition = position;
            }
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.list_item_dualline, null);
                viewHolder = new ViewHolder();

                viewHolder.station = (TextView) convertView.findViewById(R.id.list_item_station);
                viewHolder.zone = (TextView) convertView.findViewById(R.id.list_item_zone);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            viewHolder.station.setText(mWC[position].station);
            viewHolder.zone.setText(mWC[position].getzone());

            //change item color
            if(position==selectPosition){
                convertView.setBackgroundColor(Color.parseColor("#000099"));
                viewHolder.station.setTextColor(Color.parseColor("#000099"));
            }else {

            }

            return convertView;
        }
    }
}
public类FragmentWCLine扩展了android.support.v4.app.Fragment{
公共最终静态字符串EXTRA_MESSAGE=“Station_key”;
私人厕所{
专用序列站;
私有层序带;

私有类您的
意图使用的
上下文有问题,更改为:

  Intent intent = new Intent(this, mWC[position].activityClass);


如果在上下文中出现错误

做这个

Intent i = new Intent(fragment.this, activity.class); // It won't works
而是这样做

Intent i = new Intent(getActivity(), activity.class);

startActivity(i);

问题在于线路

Intent Intent=newintent(这是mWC[position].activityClass);

您必须将其更改为

Intent intent = new Intent(getActivity(),mWC[position].activityClass);

在使用onItemclick方法之前,必须定义您的意图

public class FragmentWCLine extends android.support.v4.app.Fragment {  
Intent intent;  
...  
intent = new Intent(this, mWC[position].activityClass);
Intent intent = new Intent(getActivity(),mWC[position].activityClass);
public class FragmentWCLine extends android.support.v4.app.Fragment {  
Intent intent;  
...  
intent = new Intent(this, mWC[position].activityClass);