点击提交按钮时显示错误。
database.java
package k.l;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class database extends SQLiteOpenHelper{
public static final String dbname="mydb.db";
public static final String dtab="mytution";
public static final String name="name";
public static final String passwrd="passwrd";
public static final String address="address";
public static final String email="email";
public static final String phone="phone";
public static final int dver=5;
public database(Context context, String name, CursorFactory factory,
int version) {
super(context,dbname, factory, 5);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String str="create table mytution(name text not null,passwrd text not null,address text,email text not null,phone text);";
db.execSQL(str);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
Login.java
package k.l;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class login extends Activity{
EditText name,addr,phn,pswd,emailid;
Button submit;
database db1=new database(this, "mydb.db", null, 5);
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
name=(EditText)findViewById(R.id.name);
addr=(EditText)findViewById(R.id.address);
phn=(EditText)findViewById(R.id.phn);
pswd=(EditText)findViewById(R.id.password);
emailid=(EditText)findViewById(R.id.email);
submit=(Button)findViewById(R.id.signin);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
add();
Toast.makeText(getApplicationContext(), "Succefully Registered!", 1000).show();
}
});
}
public void add(){
SQLiteDatabase sqldb=db1.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(database.name, name.getText().toString());
cv.put(database.passwrd, pswd.getText().toString());
cv.put(database.phone, phn.getText().toString());
cv.put(database.email, emailid.getText().toString());
cv.put(database.address, addr.getText().toString());
sqldb.insert(database.dtab,null, cv);
}
}
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/page2">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Name"
android:textColor="#9A32CD"
android:textStyle="bold"/>
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Password"
android:textColor="#9A32CD"
android:textStyle="bold"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textPassword"
android:id="@+id/password"
/>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Email ID"
android:textColor="#9A32CD"
android:textStyle="bold"/>
<EditText
android:id="@+id/email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone No"
android:textColor="#9A32CD"
android:textStyle="bold" />
<EditText
android:id="@+id/phn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.15"
android:inputType="number" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Address"
android:textColor="#9A32CD"
android:textStyle="bold"/>
<EditText
android:id="@+id/address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress" />
</LinearLayout>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/signin"
android:text="Create my account"
android:textStyle="bold"
android:textColor="#8B475D"
android:layout_gravity="center"/>
</LinearLayout>
错误 - 07-15 14:26:08.071:I / Database(323):sqlite返回:错误代码= 1,msg =表mytution没有名为passwrd的列
答案 0 :(得分:0)
使用ddms和sqlite manager检查数据库的步骤