グループプロジェクト用のAndroidアプリを作成していますが、次のエラーが発生します。
The constructor GradesDataSource(AddGradesFragment) is undefined
これはエラーを含むコードです:
package com.petroc.nationaldiploma;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.actionbarsherlock.app.SherlockFragment;
public class AddGradesFragment extends SherlockFragment {
private GradesDataSource datasource;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
datasource = new GradesDataSource(this);
Spinner spinner;
View view = inflater.inflate(R.layout.fragment_add_grades, container,
false);
spinner = (Spinner) view.findViewById(R.id.spinner);
List<String> list = new ArrayList<String>();
list.add("Pass");
list.add("Merit");
list.add("Distinction");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
getActivity(), android.R.layout.simple_spinner_item, list);
dataAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
spinner = (Spinner) view.findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(new CustomOnItemSelectedListener());
// EditText editText = (EditText)
// view.findViewById(R.id.editModuleText1);
return view;
}
}
これはGradesDataSourceクラスです。
package com.petroc.nationaldiploma;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
public class GradesDataSource {
// Database fields
private SQLiteDatabase database;
private MySQLiteHelper dbHelper;
private String[] allColumns = { MySQLiteHelper.COLUMN_ID,
MySQLiteHelper.COLUMN_GRADE, MySQLiteHelper.COLUMN_MODULE };
public GradesDataSource(Context context) {
dbHelper = new MySQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public Grade createGrade(String grade, String module) {
ContentValues values = new ContentValues();
values.put(MySQLiteHelper.COLUMN_GRADE, grade);
values.put(MySQLiteHelper.COLUMN_MODULE, module);
long insertId = database.insert(MySQLiteHelper.TABLE_GRADES, null,
values);
Cursor cursor = database.query(MySQLiteHelper.TABLE_GRADES,
allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
Grade newGrade = cursorToGrade(cursor);
cursor.close();
return newGrade;
}
public void deleteGrade(Grade grade) {
long id = grade.getId();
System.out.println("Grade deleted with id: " + id);
database.delete(MySQLiteHelper.TABLE_GRADES, MySQLiteHelper.COLUMN_ID
+ " = " + id, null);
}
public List<Grade> getAllGrades() {
List<Grade> grades = new ArrayList<Grade>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_GRADES,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Grade grade = cursorToGrade(cursor);
grades.add(grade);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return grades;
}
private Grade cursorToGrade(Cursor cursor) {
Grade grade = new Grade();
grade.setId(cursor.getLong(0));
grade.setGrade(cursor.getString(1));
return grade;
}
}
なぜこのエラーが発生するのですか?私はこのチュートリアルを使用しました:http ://www.vogella.com/articles/AndroidSQLite/article.html
結果のアプリは正常に機能し、グループプロジェクトのアプリにこのコードを追加しています