我有这个类,省略了代码以使其更具可读性:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;
public class TimeTrackerActivity extends Activity {
//some code here
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView) findViewById(R.id.times_list);
listView.setAdapter(timeTrackerAdapter);
TimeTrackerOpenHelper openHelper = new TimeTrackerOpenHelper(this);
//my error with line of code right above saying
//the constructor of TimeTrackerOpenHelper(TimeTrackerActivity) is undefined
}
//more code here
}
我评论了我的错误在哪里。我在网上查看了其他示例,其他所有人都将其发送到扩展 SQLiteOpenHelper 的类中,这使我认为它应该可以工作。但它不是。我的代码如下:
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class TimeTrackerOpenHelper extends SQLiteOpenHelper {
TimeTrackerOpenHelper(Context context) {
super(context, "timetracker.db", null, 1);
}
public void onCreate(SQLiteDatabase database) {/*stuff*/}
public void onUpgrade(SQLiteDatabase datbase, int oldVersion, int newVersion) {/*stuff*/}
}
我的假设是错误的吗,我是否遗漏了什么。