我尝试在我的 DatabaseHandler 类中解析一个文件,但 Eclipse 说:
方法 getAssets() 未为类型 DatabaseHandler 定义
这是代码:
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 15;
public DatabaseHandler(Context context) {
super(context, "rettinfo", null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d("Create: ", "Creating antidotlist");
String CREATE_ANTIDOT_TABLE = "CREATE TABLE antidots (id INTEGER PRIMARY KEY antidot TEXT, dos TEXT)";
Log.d("Create: ", CREATE_ANTIDOT_TABLE);
db.execSQL(CREATE_ANTIDOT_TABLE);
InputStream antidots = getAssets().open("antidot/antidots");
InputStreamReader input = new InputStreamReader(antidots);
BufferedReader buffreader = new BufferedReader(input,2*1024);
String line;
while ((line = buffreader.readLine()) != null) {
String[] point_t = line.split(",");
}
antidots.close();
}
}
蒂姆的更新
这就是日食不犯任何错误的方式
int i = 0;
InputStream antidots;
try {
antidots = mCtx.getAssets().open("antidot/antidots");
InputStreamReader input = new InputStreamReader(antidots);
BufferedReader buffreader = new BufferedReader(input,2*1024);
String line;
while ((line = buffreader.readLine()) != null) {
i++;
ContentValues values = new ContentValues();
String[] antidot = line.split("#");
int id = Integer.parseInt(antidot[0]);
values.put("id", id);
values.put("antidot", antidot[1]);
values.put("dos", antidot[2]);
db.insert("antidots", null, values);
}
antidots.close();
} catch (IOException e) {
e.printStackTrace();
}