Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “为什么我会这样?”;不兼容类型:Bla无法转换为上下文;在我的SQLiteOpenHelper构造函数中?_Java_Android_Sqlite_Android Sqlite_Sqliteopenhelper - Fatal编程技术网

Java “为什么我会这样?”;不兼容类型:Bla无法转换为上下文;在我的SQLiteOpenHelper构造函数中?

Java “为什么我会这样?”;不兼容类型:Bla无法转换为上下文;在我的SQLiteOpenHelper构造函数中?,java,android,sqlite,android-sqlite,sqliteopenhelper,Java,Android,Sqlite,Android Sqlite,Sqliteopenhelper,我正在我的Android项目中实现SQLite功能,使用 我有以下SQLiteOpenHelper代码: public class HHSSQLiteHandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_NAME = "HHS.db"; private static final Strin

我正在我的Android项目中实现SQLite功能,使用

我有以下SQLiteOpenHelper代码:

public class HHSSQLiteHandler extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "HHS.db";
    private static final String TABLE_VENDORS = "vendors";

    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_VENDORID = "vendorId";
    public static final String COLUMN_COMPANYNAME = "companyName";

    public HHSSQLiteHandler(Context context, String vendor,
                       SQLiteDatabase.CursorFactory factory, int company) {
        super(context, DATABASE_NAME, factory, DATABASE_VERSION);
    }
    . . .
…但尝试以这种方式实例化该类:

protected void onPostExecute(String result) {
    try {
        JSONArray jsonArr = new JSONArray(result);
        for (int i = 0; i < jsonArr.length(); i++) {
            JSONObject jsonObj = jsonArr.getJSONObject(i);
            String vendorId = jsonObj.getString("vendorId");
            String companyName = jsonObj.getString("companyName");
            // Prepare for writing to db
            Vendor vend = new Vendor();
            vend.setVendorId(vendorId);
            vend.setCompanyName(companyName);
            HHSSQLiteHandler sqliteHandler = new HHSSQLiteHandler(this, null, null, 1);
            sqliteHandler.addVendor(vend);
        }
    } catch (JSONException j) {
        System.out.println(j.getMessage());
        Log.i("jsonEx", j.getMessage());
    }
}
受保护的void onPostExecute(字符串结果){
试一试{
JSONArray jsonArr=新JSONArray(结果);
for(int i=0;i
…在“HHSSQLiteHandler sqliteHandler=new HHSSQLiteHandler(this,null,null,1);”行上给出“错误:不兼容的类型:MainActivity.GetVendorTask无法转换为上下文”


它到底在期待什么?我应该通过什么来安抚它

嵌套类中的此
引用嵌套类实例(
GetVendorTask
),而不是外部类实例(
MainActivity
)。使用例如
main活动对其进行限定。此
引用外部类实例,如果它是
上下文
(例如
活动
),则它将起作用