无法解决错误出现 [英] unable to resolve error appears

查看:70
本文介绍了无法解决错误出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算创建一个数据库和一个表。稍后,在活动中,在按钮单击时,我想将从屏幕接收的文本保存到表'用户'中。我在下面的行boolean中得到了'无法解决'的错误。其中accountid和accountname被标记为红色:



I intend to create a database and a table. Later, within an activity, on button click, I want to save the text received from screen into the table 'users'. I get the error like' unable to resolve' in the following line boolean.. where accountid and accountname are marked as red:

public class listmasteritems extends Activity implements  OnClickListener{
public EditText editText;
SqliteHelper sqliteHelper;
//    SQLiteDatabase db;
    String AccountName;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listmasteritems);
        editText = (EditText)findViewById(R.id.idRelationShip);
        editText.setOnClickListener(this);
    sqliteHelper = new SqliteHelper(this);
    }

    public void onBtnIncludeClick( View v)
    {
        boolean result = sqliteHelper.saveUser(accountid,accountname);


SqlliteHelper:

public class SqliteHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "MyDatabase";
    private static final int DATABASE_VERSION = 1;
    public SqliteHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE users " +
                "(accountid INT PRIMARY KEY, accountname text)";
        db.execSQL(sql);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i2) {
        db.execSQL("DROP TABLE IF EXISTS users");
        onCreate(db);
    }

    public boolean saveUser (String accountid, String accountname)
    {
        Cursor cursor = getUser(accountname);
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put("accountname", accountname);
        //contentValues.put("hobbies", hobbies);
        //contentValues.put("zodiac", zodiac);
        long result;
        if (cursor.getCount() == 0) { // Record does not exist
            contentValues.put("accountname", accountname);
            result = db.insert("users", null, contentValues);
        } else { // Record exists
            result = db.update("users", contentValues, "ac=?", new String[] { accountname });
        }

        if (result == -1) {
            return false;
        } else {
            return true;
        }
    }

推荐答案

以下代码段不完整...

The following piece of your code is incomplete ...
public void onBtnIncludeClick( View v)
{
    boolean result = sqliteHelper.saveUser(accountid,accountname);



和变量 accountid accountname 没有在任何地方宣布。



此外,当你发布你的消息时,请不要说我收到像...... 这样的消息。发布确切的消息并在代码中指出它发生的确切位置。


and the variables accountid and accountname are not declared anywhere.

Also, when you post your message please don't say I get a message like .... Post the exact message and indicate in your code the exact point at which it occurs.


这篇关于无法解决错误出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆