我有这段代码,用于验证用户输入密码(密码已由密码定义)。现在,如果密码正确,那么他将进入下一个在数据库中添加内容的过程。除了这个错误,进程已经没问题。提前致谢。希望你帮我这个:(
package info.androidhive.slidingmenu;
import info.androidhive.slidingmenu.MainActivity;
import info.androidhive.slidingmenu.ObjectStudent;
import info.androidhive.slidingmenu.DatabaseFragment;
import info.androidhive.slidingmenu.R;
import info.androidhive.slidingmenu.TableControllerStudent;
import android.R.string;
import android.app.Fragment;
import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class DatabaseFragment extends Fragment
{
public DatabaseFragment(){}
Context thiscontext;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
thiscontext = container.getContext();
RelativeLayout mRelativeLayout = (RelativeLayout) inflater.inflate(R.layout.fragment_database,
container, false);
Button buttonCreateLocation = (Button) mRelativeLayout.findViewById(R.id.buttonCreateStudent);
buttonCreateLocation.setOnClickListener(new OnClickListener()
{
public void onClick(View views)
{
final Context context = views.getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View formElementsView = inflater.inflate(R.layout.login_input_form, null, false);
final EditText usernamea = (EditText) formElementsView.findViewById(R.id.username);
final EditText passworda = (EditText) formElementsView.findViewById(R.id.password);
new AlertDialog.Builder(context)
.setView(formElementsView)
.setTitle("Login")
.setPositiveButton("Submit",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
Editable password = null;
if (passworda.getText()== password)
{
@Override
public void onClick(View view) //THE ERROR IS LOCATED HERE
{
final Context context = view.getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View formElementsView = inflater.inflate(R.layout.student_input_form, null, false);
final EditText editTextStudentFirstname = (EditText) formElementsView.findViewById(R.id.editTextStudentFirstname);
final EditText editTextStudentEmail = (EditText) formElementsView.findViewById(R.id.editTextStudentEmail);
final EditText editTextStudentCategory = (EditText) formElementsView.findViewById(R.id.editTextStudentCategory);
new AlertDialog.Builder(context)
.setView(formElementsView)
.setTitle("Create Translation")
.setPositiveButton("Add",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
String studentFirstname = editTextStudentFirstname.getText().toString();
String studentEmail = editTextStudentEmail.getText().toString();
String studentCategory = editTextStudentCategory.getText().toString();
ObjectStudent objectStudent = new ObjectStudent();
objectStudent.firstname = studentFirstname;
objectStudent.email = studentEmail;
objectStudent.category = studentCategory;
boolean createSuccessful = new TableControllerStudent(context).create(objectStudent);
if(createSuccessful)
{
Toast.makeText(context, "Student information was saved.", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(context, "Unable to save student information.", Toast.LENGTH_SHORT).show();
}
((MainActivity) context).countRecords();
((MainActivity) context).readRecords();
dialog.cancel();
}
}).show();
}
}
else
{
dialog.cancel();
}
}
});
return mRelativeLayout;
}
});
}
}
这是数据库
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
protected static final String DATABASE_NAME = "StudentDatabase";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE students " +
"( id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"firstname TEXT, " +
"username TEXT, " +
"password TEXT, " +
"email TEXT, "
+ "category TEXT ) ";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "DROP TABLE IF EXISTS students";
db.execSQL(sql);
onCreate(db);
}
}
答案 0 :(得分:0)
multiple markers at this line
这个异常是由SQLite异常抛出的,你应该发布你的数据库填充代码,以及Logcat输出;)
顺便欢迎!
编辑:您应该总是使用如下字符串类型来处理if-clauses:.equals("")
而不是:==