根据android studio,在任何java类中都没有错误,但是没有发生数据插入。
我的Register_Page.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register__page);
Name = (EditText) findViewById(R.id.editText_name);
Email = (EditText) findViewById(R.id.editText_email);
Pass = (EditText) findViewById(R.id.editText_pass);
Phone = (EditText) findViewById(R.id.editText_phone);
City = (EditText) findViewById(R.id.editText_city);
DOB = (EditText) findViewById(R.id.editText_dob);
helper = new no.nordicsemi.android.nrftoolbox.myDbAdapter(this);
}
public void addUser(View view) {
RadioGroup radio_Group = (RadioGroup) findViewById(R.id.radioGroup);
int radioButtonID = radio_Group.getCheckedRadioButtonId();
RadioButton radioButton = (RadioButton)
radio_Group.findViewById(radioButtonID);
Gender = (String) radioButton.getText();
String t1 = Name.getText().toString();
String t3 = Pass.getText().toString();
String t2 = Email.getText().toString();
String t5 = DOB.getText().toString();
String t6 = Phone.getText().toString();
String t7 = City.getText().toString();
String t4 = Gender;
if (t1.isEmpty() || t2.isEmpty() || t3.isEmpty() || t4.isEmpty() ||
t5.isEmpty() || t6.isEmpty() || t7.isEmpty()) {
no.nordicsemi.android.nrftoolbox.Message.message(getApplicationContext(),
"Enter Required Fields");
} else {
long id = helper.insertData(t1, t2, t3, t4, t5, t6, t7);
if (id <= 0) {
no.nordicsemi.android.nrftoolbox.Message.message(getApplicationContext(),
"Insertion Unsuccessful");
Name.setText("");
Pass.setText("");
Email.setText("");
DOB.setText("");
Phone.setText("");
City.setText("");
} else {
no.nordicsemi.android.nrftoolbox.Message.message(getApplicationContext(),
"Insertion Successful");
Name.setText("");
Pass.setText("");
Email.setText("");
DOB.setText("");
Phone.setText("");
City.setText("");
}
}
}
}
我的myDBHelper.java如下:
r
package no.nordicsemi.android.nrftoolbox;
public long insertData(String name, String email,String pass,String
gender,String dob,String phone ,String city)
{
SQLiteDatabase dbb = myhelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(myDbHelper.NAME, name);
contentValues.put(myDbHelper.MyPASSWORD, pass);
contentValues.put(myDbHelper.EMAIL,email);
contentValues.put(myDbHelper.DOB,dob);
contentValues.put(myDbHelper.GENDER,gender);
contentValues.put(myDbHelper.PHONE,phone);
contentValues.put(myDbHelper.CITY,city);
long id = dbb.insert(myDbHelper.TABLE_NAME, null , contentValues);
return id;
}
static class myDbHelper extends SQLiteOpenHelper
{
private static final String DATABASE_NAME = "myDatabase"; //
Database Name
private static final String TABLE_NAME = "myTable"; // Table Name
private static final int DATABASE_Version = 1; // Database
Version
private static final String UID="_id"; // Column I (Primary Key)
private static final String NAME = "Name"; //Column II
private static final String MyPASSWORD= "Password";// Column III
private static final String EMAIL = "Email-id";//Column IV
private static final String GENDER="Gender";
private static final String CITY="City";
private static final String DOB="DOB";
private static final String PHONE="Phone No.";
private static final String CREATE_TABLE = " CREATE TABLE
"+TABLE_NAME+" ( "+
UID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
NAME+" TEXT, "+
EMAIL+ " TEXT NOT NULL, "+
MyPASSWORD+" TEXT, "+
GENDER+" TEXT NOT NULL, "+
DOB+" TEXT NOT NULL, "+
PHONE+" INTEGER NOT NULL, "+
CITY+" TEXT );";
private static final String DROP_TABLE ="DROP TABLE IF EXISTS
"+TABLE_NAME;
private Context context;
public myDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_Version);
this.context=context;
}
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(CREATE_TABLE);
} catch (Exception e) {
no.nordicsemi.android.nrftoolbox.Message.message(context,""+e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
try {
no.nordicsemi.android.nrftoolbox.Message.message(context,"OnUpgrade");
db.execSQL(DROP_TABLE);
onCreate(db);
}catch (Exception e) {
no.nordicsemi.android.nrftoolbox.Message.message(context,""+e);
}
}
}
}
我的Register_page.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="no.nodicsemi.android.nrftoolbox.Register_Page">
<RelativeLayout
android:id="@+id/textView_phone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/editText_name"
android:layout_alignParentTop="true"
android:layout_marginLeft="100dp"
android:layout_marginTop="28dp"
android:layout_weight="0.36"
android:text="Register Here"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#3333ff"
android:textSize="28dp" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="viewdata"
android:text="Button" />
<TextView
android:id="@+id/textView_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14sp"
android:layout_marginTop="70sp"
android:autoText="false"
android:text="Name :"
android:textColor="#3368ff"
android:textColorLink="#000000"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_marginTop="100sp"
android:ems="10"
android:hint="Enter your name"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14sp"
android:layout_marginTop="160sp"
android:text="Email-id :"
android:textColor="#3368ff"
android:textColorLink="#000000"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_marginTop="190sp"
android:ems="10"
android:hint="Enter Email-id"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/textView_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:layout_marginTop="250dp"
android:hint="Enter Password"
android:text="Password"
android:textColor="#3368ff"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="280dp"
android:ems="10"
android:hint="Enter Password"
android:inputType="textPassword" />
<TextView
android:id="@+id/textView_dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14sp"
android:layout_marginTop="450sp"
android:text="Date of Birth :"
android:textColor="#3368ff"
android:textColorLink="#000000"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_dob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="480dp"
android:ems="10"
android:hint="Date of Birth"
android:inputType="date" />
<TextView
android:id="@+id/textView_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14sp"
android:layout_marginTop="540sp"
android:text="Phone No. :"
android:textColor="#3368ff"
android:textColorLink="#000000"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_marginTop="570sp"
android:ems="10"
android:hint="Enter Phone No."
android:inputType="phone" />
<TextView
android:id="@+id/textView_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14sp"
android:layout_marginTop="630sp"
android:text="City :"
android:textColor="#3368ff"
android:textColorLink="#000000"
android:textSize="20sp" />
<EditText
android:id="@+id/editText_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_marginTop="660sp"
android:ems="10"
android:hint="Enter your City"
android:inputType="textPersonName" />
<TextView
android:id="@+id/textView_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14sp"
android:layout_marginTop="340sp"
android:text="Gender :"
android:textColor="#3368ff"
android:textColorLink="#000000"
android:textSize="20sp" />
<Button
android:id="@+id/button_register"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="720dp"
android:background="#3368ff"
android:onClick="addUser"
android:text="Register"
android:textAlignment="center"
android:textColor="#ffffff" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="340sp">
<RadioButton
android:id="@+id/radioButton_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120sp"
android:layout_weight="1"
android:text="Male"
android:textSize="18sp" />
<RadioButton
android:id="@+id/radioButton_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120sp"
android:layout_weight="1"
android:text="Female"
android:textSize="18sp" />
<RadioButton
android:id="@+id/radioButton_other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120sp"
android:layout_weight="1"
android:text="Other"
android:textSize="18sp" />
</RadioGroup>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
我没有收到任何错误,但数据没有插入..它总是显示&#34;插入不成功&#34;。
有人可以告诉我问题在哪里吗?