我在CourseInnerPage活動內部創建了一個構造函數,並在OnBindViewHolder方法內調用它,並在輸入時傳遞了getItemCount。但我得到一個異常,並在我的manifest.xml文件中說,這個活動沒有默認的構造函數。我該怎麼辦?有關此活動的清單錯誤沒有默認構造函數
適配器類:
public class AdapterVRList extends RecyclerView.Adapter<AdapterVRList.CourseViewHolder> {
private Context context;
private List<DObjectVrList> DObjectVrListList;
public AdapterVRList(Context context, List<DObjectVrList> DObjectVrListList){
this.context = context;
this.DObjectVrListList = DObjectVrListList;
}
public AdapterVRList(Context context){
}
@Override
public CourseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.card_vr,parent,false);
return new CourseViewHolder(view);
}
@Override
public void onBindViewHolder(CourseViewHolder holder, int position) {
DObjectVrList DObjectVrList = DObjectVrListList.get(position);
holder.CourseText.setText(DObjectVrList.getTitleCourse());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CourseInnerPage course = new CourseInnerPage(getItemCount());
Intent intent = new Intent(context,CourseInnerPage.class);
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return 8;
}
public class CourseViewHolder extends RecyclerView.ViewHolder{
private TextView CourseText;
public CourseViewHolder(View itemView) {
super(itemView);
CourseText = (TextView) itemView.findViewById(R.id.course_text);
}
}
}
CourseInnerPage活性:
public class CourseInnerPage extends AppCompatActivity {
private static final String TAG = "CourseInnerPage";
private FloatingActionButton ShowButton;
private NestedScrollView CourseShow;
private int id;
public CourseInnerPage(int Id_Card){
id = Id_Card;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course_inner_page);
CourseShow = (NestedScrollView) findViewById(R.id.course_descript);
CourseShow.setVisibility(View.INVISIBLE);
CoordinatorLayout layout = (CoordinatorLayout) findViewById(R.id.inner_course);
for(int i=1;i<=8;i++){
switch (id) {
case 1:
layout.setBackground(getResources().getDrawable(R.drawable.one_bg, null));
ShowButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TeacherNet teacherNet = new TeacherNet(CourseInnerPage.this);
JSONObject requestObject = new JSONObject();
try {
requestObject.put("vrcode","1");
teacherNet.SelectContent(requestObject, new TeacherNet.JSONsendListener() {
@Override
public void JSONsent(String success) {
if (success=="OK"){
Log.i(TAG, "JSONsent: Everything is Ok");
}
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
});
break;
case 2:
layout.setBackground(getResources().getDrawable(R.drawable.two_bg, null));
break;
case 3:
layout.setBackground(getResources().getDrawable(R.drawable.three_bg,null));
break;
case 4:
layout.setBackground(getResources().getDrawable(R.drawable.four_bg,null));
break;
case 5:
layout.setBackground(getResources().getDrawable(R.drawable.five_bg,null));
break;
case 6:
layout.setBackground(getResources().getDrawable(R.drawable.six_bg,null));
break;
case 7:
layout.setBackground(getResources().getDrawable(R.drawable.seven_bg,null));
break;
case 8:
layout.setBackground(getResources().getDrawable(R.drawable.eight_bg,null));
break;
}
}
}
}
AndroidManifest文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="realup.ir.teacher">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Teacher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Activity.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity.Main"
android:parentActivityName=".Activity.Student">
<meta-data
android:name="android.support.PARENT_ACTIVTY"
android:value=".Student" />
</activity>
<activity android:name=".Activity.Student" />
<activity android:name=".Activity.CourseInnerPage"/>
</application>
</manifest>
抗辯n:java.lang.InstantiationException:java.lang.Class沒有零參數構造函數
再次感謝你;) –