提示:若报错,检查包名是否一致,还有在AndroidManifest.xml中是否配置好
MainActivity.java文件代码
package com.example.wzx.myapplication;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
MyHelper myHelper;
private EditText mEtName;
private EditText mEtPhone;
private EditText mEtEmail;
private TextView mTvShow;
private Button mBtAdd;
private Button mBtQuery;
private Button mBtUpdate;
private Button mBtDelete;
public String name;
public String phone;
public String email;
public SQLiteDatabase db;
public ContentValues values;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myHelper = new MyHelper(this);
init();
}
//实例化界面,获取各个控件的值
private void init() {
mEtName = (EditText) findViewById(R.id.et_name);
mEtPhone = (EditText) findViewById(R.id.et_phone);
mEtEmail = (EditText) findViewById(R.id.et_email);
mTvShow = (TextView) findViewById(R.id.ld_show);
mBtAdd = (Button) findViewById(R.id.btn_add);
mBtUpdate = (Button) findViewById(R.id.btn_update);
mBtQuery = (Button) findViewById(R.id.btn_query);
mBtDelete = (Button) findViewById(R.id.btn_delete);
mBtAdd.setOnClickListener(this);
mBtUpdate.setOnClickListener(this);
mBtQuery.setOnClickListener(this);
mBtDelete.setOnClickListener(this);
}
@Override
//点击事件
public void onClick(View v) {
switch(v.getId()) {