Я создаю приложение для входа в Android, я выполнил загрузку базы данных в эмулятор. Когда я добавляю базу данных, используя созданное мной приложение, эмулятор перестает работать и перестает отвечать. Что мне делать?
package com.android.sms.privacy;
import java.util.Arrays;
import java.util.Locale;
import com.android.sms.privacy.DatabaseHelper;
import android.app.Activity;
import android.widget.EditText;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;
public class SMS extends Activity {
//
public static final String DEBUG_TAG = "FullDatabase Log";
public static final int DB_version = 2;
//public static final String DB_name = "User.db";
public static final String TABLE_NAME = "login";
//public static final String TABLE_NAME = "tbl_temp";
//public static final String DB_name = "User_temp";
public static final String DBNAME = "login";
public DatabaseHelper database_helper;
public SQLiteDatabase database;
public SQLiteDatabase database_rd;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.createaccount);
Toast.makeText(this,"Before Bundled",
Toast.LENGTH_SHORT).show();
createDataBase();
//LogIn login = new LogIn();
Button submit = (Button)findViewById(R.id.Button02);
Toast.makeText(this,"after Bundled",
Toast.LENGTH_SHORT).show();
submit.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Welcome createaccount = new Welcome();
Toast.makeText(createaccount.getApplicationContext(), "In Helper executing onCreate1()",
Toast.LENGTH_SHORT).show();
String[] success = insertRecords();
if(success[0].equalsIgnoreCase("1"))
{
setContentView(R.layout.menu);
}
}
});
//database.close();
}
//
protected String[] insertRecords() {
Toast.makeText(this,"In insertrecords", Toast.LENGTH_SHORT).show();
//database.openDatabase(DB_name,database.create(factory),
//ACCESSIBILITY_SERVICE);
final EditText username = (EditText)findViewById(R.id.username);
final EditText password = (EditText)findViewById(R.id.password);
Long newUserID = 0l;
String user = username.getText().toString();
String userpass = password.getText().toString();
ContentValues values = new ContentValues();
values.put("username",user);
values.put("password",userpass);
//StringBuilder info = new StringBuilder();
String[] info = new String[10];
database.beginTransaction();
try
{
Toast.makeText(this,"Before calling inserting values",
Toast.LENGTH_SHORT).show();
newUserID = database.insertOrThrow(TABLE_NAME, null, values);
Toast.makeText(this,"After calling inserting values",
Toast.LENGTH_SHORT).show();
info[0] = newUserID.toString();
info[1] = user;
info[2] = userpass;
System.out.println(newUserID);
Toast.makeText(this, newUserID.toString(),
Toast.LENGTH_SHORT).show();
Cursor c = database_rd.query(TABLE_NAME, null, null, null, null,
null,null);
LogCursorInfo(c);
c.close();
}
catch(Exception e)
{
//Transaction failed;
e.printStackTrace();
}
finally
{
database.endTransaction();
database.close();
}
return info;
}
private void LogCursorInfo(Cursor c) {
// TODO Auto-generated method stub
Log.i(DEBUG_TAG, "*** Cursor Begin *** " + " Results:" +
c.getCount() + " Columns: " + c.getColumnCount());
// Print column names
String rowHeaders = "|| ";
for (int i = 0; i < c.getColumnCount(); i++) {
rowHeaders = rowHeaders.concat(c.getColumnName(i) + " || ");
}
Log.i(DEBUG_TAG, "COLUMNS " + rowHeaders);
//Integer rows = c.getCount();
//Toast.makeText(this, rows.toString(), Toast.LENGTH_SHORT).show();
// Print records
c.moveToFirst();
while (c.isAfterLast() == false) {
String rowResults = "|| ";
for (int i = 0; i < c.getColumnCount(); i++) {
rowResults = rowResults.concat(c.getString(i) + " || ");
}
Log.i(DEBUG_TAG, "Row " + c.getPosition() + ": " + rowResults);
Toast.makeText(this, rowResults.toString(),
Toast.LENGTH_SHORT).show();
//Toast.makeText(this, "In LogCursorInfo",
c.moveToNext();
}
Log.i(DEBUG_TAG, "*** Cursor End ***");
}
void createDataBase()
{
if(Arrays.binarySearch(databaseList(), DBNAME)>=0)
{
deleteDatabase(DBNAME);
}
database_helper = new
DatabaseHelper(this.getApplicationContext());
//database_helper.onCreate(database);
database = database_helper.getWritableDatabase();
database.setLocale(Locale.getDefault()); // Set the local
database.setLockingEnabled(true); // SQLiteDatabase is made thread-safe by using locks around critical sections.
database_rd = database_helper.getReadableDatabase();
Toast.makeText(this, "created database",
Toast.LENGTH_SHORT).show();
/*
database =
openOrCreateDatabase(DB_name,SQLiteDatabase.CREATE_IF_NECESSARY,
null);
database.setLocale(Locale.getDefault()); // Set the local
database.setLockingEnabled(true); // SQLiteDatabase is made
thread-safe by using locks around critical sections.
database.setVersion(1);
database.execSQL(CREATE_USER_TABLE);
*/
}
}
Приложение перестает отвечать в этой точке:
submit.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Welcome createaccount = new Welcome();
Toast.makeText(createaccount.getApplicationContext(), "In Helper executing onCreate1()",
Toast.LENGTH_SHORT).show();
String[] success = insertRecords();
if(success[0].equalsIgnoreCase("1"))
{
setContentView(R.layout.menu);
}
}
});