Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.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
Android 无法将位置设置为字符串_Android_Database_Sqlite - Fatal编程技术网

Android 无法将位置设置为字符串

Android 无法将位置设置为字符串,android,database,sqlite,Android,Database,Sqlite,嗨,我不知道为什么我的一个列表出错。它表示我的“位置”不能放为字符串。此外,我还硬编码了我的位置和地址,因为我不需要用户输入任何地址(我以微调器的形式输入了地址)。因此,我尝试将我的“位置”和“地址”硬编码到我的SQLite数据库中。我可以将其他微调器存储到数据库中。所以请帮帮我 数据库适配器: public class DBAdapter { private static final String TAG = "DBAdapter"; private static fina

嗨,我不知道为什么我的一个列表出错。它表示我的“位置”不能放为字符串。此外,我还硬编码了我的位置和地址,因为我不需要用户输入任何地址(我以微调器的形式输入了地址)。因此,我尝试将我的“位置”和“地址”硬编码到我的SQLite数据库中。我可以将其他微调器存储到数据库中。所以请帮帮我

数据库适配器:

public class DBAdapter {

    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "powerfood2014";
    private static final int DATABASE_VERSION = 2;

public static final String KEY_RESTID = "locationId";
    public static final String KEY_LOCATION = "location";
    private static final String LOCATION_TABLE = "location";

private static final String CREATE_LOCATION =
            "create table if not exists location (locationId integer primary key autoincrement, " + "location VARCHAR);";

private final Context context;

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBAdapter(Context ctx)
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    private static class DatabaseHelper extends SQLiteOpenHelper
    {
        DatabaseHelper(Context context)
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL(CREATE_LOCATION);
        }

  @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            db.execSQL("DROP TABLE IF EXISTS " + CREATE_LOCATION);
            onCreate(db);
        }
    }
//---opens the database---
    public DBAdapter open() throws SQLException
    {
        db = DBHelper.getWritableDatabase();
        return this;
    }

    //---closes the database---
    public void close()
    {
        DBHelper.close();
    }
 public long insertLocation(String location, String address) {

        ContentValues initialValues = new ContentValues();

        initialValues.put(KEY_LOCATION, "Somerset 313 Powerfood");
        db.insert(LOCATION_TABLE, null, initialValues);

        initialValues.put(KEY_LOCATION, "Vivo City Powerfood");
        db.insert(LOCATION_TABLE, null, initialValues);

        //insert row
        long locationId = db.insert(LOCATION_TABLE, null, initialValues);

        return locationId;
    }
}
这是我的位置课程:

public class Location extends Activity {
Spinner spinner1;
    private Button btnSubmit;
    DBAdapter db = new DBAdapter(this);

public void buttonOnClickL(View v) {

        Log.d("test", "adding");
        //get data from form
        Spinner location = (Spinner)findViewById(R.id.spinner1);

        db.open();
        long id = db.insertLocation(location.getSelectedItem().toString());
        db.close();


        Toast.makeText(Location.this, "Customer successfully registered", Toast.LENGTH_LONG).show();

        startActivity(new Intent(getApplicationContext(), HomePage.class));


    }
}
日志:

    error: method insertLocation in class DBAdapter cannot be applied to given types;
    required: String,String
    found: String
    reason: actual and formal argument lists differ in length
错误:类AdapterView中的方法setOnItemSelectedListener无法应用于给定类型; 必需:OnItemSelectedListener 发现:位置 原因:无法通过方法调用转换将实际参数位置转换为OnItemSelectedListener 其中T是一个类型变量: T扩展AdapterView类中声明的适配器,如日志中所述:

错误:无法将DBAdapter类中的insertLocation方法应用于 给定类型

因为
insertLocation
方法接受两个字符串参数,而不是一个,并且在从活动调用insertLocation方法时只传递一个参数

    String str_location=location.getSelectedItem().toString();
    long id = db.insertLocation(str_location,<PASS_SECOND_PARAM_HERE>);
String str_location=location.getSelectedItem().toString();
long id=db.insertLocation(str_location,);

如果要删除第二个参数,它会给我新的错误日志。(更新日志)