数据库无法解析为变量

时间:2015-04-24 06:11:30

标签: java android database sqlite

创建数据库时出错,它指示错误字“数据库”并显示错误:

Database cannot be resolved a variable

所以请告诉我如何纠正它。

package com.flocater;
import com.flocator.R;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class AddFriends extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addfriends);
    }

    public void addFriend(View v) {
        // get access to views
        EditText editName = (EditText) this.findViewById(R.id.editName1);
        EditText editPhone = (EditText) this.findViewById(R.id.editPhone1);
        EditText editArea = (EditText) this.findViewById(R.id.editArea1);
        EditText editCity = (EditText) this.findViewById(R.id.editCity1);

        try {
            DBHelper dbhelper = new DBHelper(this);
            SQLiteDatabase db = dbhelper.getWritableDatabase();
            Log.d("Account", "Got Writable database");
            // execute insert command

            ContentValues values = new ContentValues();
            values.put(Database.FRIENDS_NAME, editName.getText().toString());
            values.put(Database.FRIENDS_PHONE, editPhone.getText().toString());// "The error was displayed in the word Database"
            values.put(Database.FRIENDS_AREA, editArea.getText().toString());
            values.put(Database.FRIENDS_CITY, editCity.getText().toString());

            long rows = db.insert(Database.FRIENDS_TABLE_NAME, null, values);
            db.close();
            if (rows > 0) {
                Toast.makeText(this, "Added Friend Successfully!",
                        Toast.LENGTH_LONG).show();
                this.finish();
            } else
                Toast.makeText(this, "Sorry! Could not add Friend!",
                        Toast.LENGTH_LONG).show();

        } catch (Exception ex) {
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();//print message
        }

    }``
}

2 个答案:

答案 0 :(得分:0)

您没有共享DBHelper类,但是根据可用信息,我认为您应该在 ALL 中尝试使用DBHelper而不是数据库使用values.put()的行。

Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

还有插入方法:

 values.put(DBHelper.FRIENDS_NAME, editName.getText().toString());
 values.put(DBHelper.FRIENDS_PHONE, editPhone.getText().toString());
 values.put(DBHElper.FRIENDS_AREA, editArea.getText().toString());
 values.put(DBHelper.FRIENDS_CITY, editCity.getText().toString());

一切顺利

答案 1 :(得分:0)

对于异常,请调试并验证您在<li ng-repeat="cover in accSummary.response.covers"> <div class="account-detail-row col-xs-12 col-sm-12 col-md-12 padding-left12 padding-right12 padding-top24 padding-bottom12"> <h4 class="font-16 fontwt-400" ng-hide="cover.coverAmt <= 0">Current insurance cover</h4> </div> </li> 第36行创建的SQL脚本。

以下是您的代码创建的查询:Friendfinderactivity,其语法错误。

这就是问题所在。