-1

对不起,我是个初学者,

我有一个简单的应用程序,将数据存储在一个页面上并在另一个页面上获取它。当我尝试获取数据时,我不断收到错误消息,指出找不到这样的列。请帮忙

这是我输入数据的代码,EnterDetails.java

            @Override
        public void onClick(View arg0) {
            EditText holdersala = (EditText) findViewById(R.id.rawsalary);
            EditText wantspercentage = (EditText) findViewById(R.id.wantspercent);
            EditText needspercentage = (EditText) findViewById(R.id.needspercent);

            String holdersalary = holdersala.getText().toString();
            final int salary = Integer.parseInt(holdersalary);

            String holderwantsp = wantspercentage.getText().toString();
            final int wantsp = Integer.parseInt(holderwantsp);

            String holderneedsp = needspercentage.getText().toString();
            final int needsp = Integer.parseInt(holderneedsp);

            if(wantsp + needsp <= 100){

                DatabaseAdapter databaseAdapter = new DatabaseAdapter(getApplicationContext());
                databaseAdapter.open();
                databaseAdapter.createRecordS(salary);
                databaseAdapter.createRecordW(wantsp);
                databaseAdapter.createRecordN(needsp);
                databaseAdapter.close();

                startActivity(new Intent(EnterDetails.this, Summary.class));
            } else {
            } 

            Toast toast = Toast.makeText(EnterDetails.this, "incorrect data", 5000);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show(); 
        }
    });

我从中获取数据的代码

        TextView bn = (TextView) findViewById(R.id.budget_need);


     DatabaseAdapter databaseAdapter = new DatabaseAdapter(getApplicationContext());
        databaseAdapter.open();
        bn.setText(databaseAdapter.fetchRecordS(1));
        databaseAdapter.close();

和我的 databaseAdapter.java 中的代码

  public class DatabaseAdapter {

private Context context;
private SQLiteDatabase database;
private DatabaseOpenHelper dbHelper;

public DatabaseAdapter(Context context) {
    this.context = context;
}
public DatabaseAdapter open() throws SQLException {
    dbHelper = new DatabaseOpenHelper(context);
    database = dbHelper.getWritableDatabase();
    return this;
}

public void close() {
    dbHelper.close();
}
public long createRecordS(int interger) {
    ContentValues contentValue = new ContentValues();        
    contentValue.put("salafig", interger);            
    return database.insert("maindata", null, contentValue);
}
public long createRecordN(int interger) {
    ContentValues contentValue = new ContentValues();        
    contentValue.put("needsper", interger);            
    return database.insert("maindata", null, contentValue);
}
public long createRecordW(int interger) {
    ContentValues contentValue = new ContentValues();        
    contentValue.put("wantsper", interger);            
    return database.insert("maindata", null, contentValue);
}
public int fetchRecordS(long rowId) throws SQLException {
    Cursor mCursor = database.query(true, "maindata", new String[] { "salafig",
            "needsper", "wantsper" }, "salafig"+ rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
        return (mCursor.getInt(1));
    }
    return (Integer) null;
}
public int fetchRecordW(long rowId) throws SQLException {
    Cursor mCursor = database.query(true, "maindata", new String[] { "salafig",
            "needsper", "wantsper" }, "wantsper"+ rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
        return (mCursor.getInt(1));
    }
    return (Integer) null;
}public int fetchRecordN(long rowId) throws SQLException {
    Cursor mCursor = database.query(true, "maindata", new String[] { "salafig",
            "needsper", "wantsper" }, "needsper"+ rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
        return (mCursor.getInt(1));
    }

如果提前提供任何帮助,希望这是有道理的。

4

1 回答 1

0

查看这里以检查 SQLiteDatabase 查询方法的正确语法。该方法的第四个参数是选择条件,它应该是这样的:

"salafig = "+ rowId"

而不是这个:

"salafig"+ rowId"
于 2013-08-14T23:44:28.027 回答