English 中文(简体)
利用贝 和甲状腺素基
原标题:Constructing database using eclipse android sqlite

The code is for the registation table for finace app The user registers into the app and it is stored into the database later it will used to login into app my problem is here that the database is being created but the table is not getting created and the appication is closing if we click on the submit button similarly with the reset button

实际应当将数据输入表格,但

public class Register extends Activity  {
        String str1;
     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.register);

返回原木页

            Button bk=(Button)findViewById(R.id.back);

            bk.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent1=new Intent(v.getContext(), PersonelFinaceAppActivity.class);
                    startActivityForResult(intent1, 0);

                }
            });

button for the reset button it resets all the fields

            Button rst=(Button)findViewById(R.id.reset);
            rst.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    EditText et=(EditText)findViewById(R.id.fn);
                    et.setText("");
                    et=(EditText)findViewById(R.id.ln);
                    et.setText("");
                    et=(EditText)findViewById(R.id.un);
                    et.setText("");
                    et=(EditText)findViewById(R.id.pass);
                    et.setText("");
                    et=(EditText)findViewById(R.id.monincome);
                    et.setText("");
                    TextView tv =(TextView)findViewById(R.id.textView1);
                    tv.setText("Firstname ");
                    tv =(TextView)findViewById(R.id.textView2);
                    tv.setText("Lastname");
                    tv =(TextView)findViewById(R.id.textView3);
                    tv.setText("Username");
                    tv =(TextView)findViewById(R.id.textView6);
                    tv.setText("Password");
                    tv =(TextView)findViewById(R.id.textView7);
                    tv.setText("Monthlyincome");
                }
            });

check button for checking the useralready exits in the database of not

            Button chk=(Button)findViewById(R.id.chk);
            chk.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        String User;
                        EditText Username = (EditText)findViewById(R.id.un);
                        User = Username.getEditableText().toString().trim();
                        SQLiteDatabase db1;
                        db1 = openOrCreateDatabase("Userdetails.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
                        db1.setVersion(3);
                        db1.setLocale(Locale.getDefault());
                        db1.setLockingEnabled(true);
                    try{Cursor c1=db1.rawQuery("select Username from details1 where Username= "+User+" ",null);
                                if(c1.moveToNext()){showDialog(1);}
                                else{showDialog(2);}
                            }
                        catch (Exception e) {
                            // TODO: handle exception
                            }
                        }
                });

the problem arises here the submit button it has to perform all the action of the app

            Button sub=(Button)findViewById(R.id.submit);
            sub.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view)  {
                    // TODO Auto-generated method stub

                        String First;
                        String Last;
                        String User;
                        String Pass;
                        String monthincome;
                        @SuppressWarnings("unused")
                        long l;
                        EditText Firstname =(EditText)findViewById(R.id.fn);
                        EditText Lastname = (EditText)findViewById(R.id.ln);
                        EditText Username = (EditText)findViewById(R.id.un);
                        EditText Password = (EditText)findViewById(R.id.pass);
                        EditText moninc = (EditText)findViewById(R.id.monincome);
                        First = Firstname.getEditableText().toString().trim();
                        Last = Lastname.getEditableText().toString().trim();
                        Pass = Password.getEditableText().toString().trim();
                        User = Username.getEditableText().toString().trim();
                        monthincome = moninc.getEditableText().toString().trim();
                        if(Firstname.length()<1 || Lastname.length()<1 || Password.length()<1 || Username.length()<1 || moninc.length()<1)
                        {showDialog(3);}
                        else{SQLiteDatabase db1;
                                    db1 = openOrCreateDatabase("Userdetails.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
                                    db1.setVersion(3);
                                    db1.setLocale(Locale.getDefault());
                                    db1.setLockingEnabled(true);
                                    final String CREATE_TABLE_DETAILS ="CREATE TABLE details1 (" + "Username INTEGER PRIMARY KEY ," + "Firstname TEXT," + "Lastname TEXT," + "Password TEXT," + "Monthlyincome TEXT);"; 
                            db1.execSQL(CREATE_TABLE_DETAILS); 
                            try{Cursor c1=db1.rawQuery("select Username from details1 where Username= "+User+" ",null);
                                        if(c1.moveToNext())
                                        {showDialog(4);}
                                        else{
                                        ContentValues values1 = new ContentValues();
                                        values1.put("Firstname", First);
                                        values1.put("Lastname", Last);
                                        values1.put("Username", User);
                                        values1.put("Password", Pass);
                                        values1.put("Monthlyincome", monthincome);
                                        db1.insert("details1", null, values1);
                                        showDialog(5);
                                        }
                                        }
                                        catch(Exception e)
                                        {}
                                        finally
                                        {}
                        }
                    }
            });
     }

}  

需要帮助的只是提交国的pl。

最佳回答

表中数字

a. 地理分布

db1 = openOrCreateDatabase("Userdetails.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);

db1.setVersion(3); db1.setLocale(Locale.getDefault());

db1.setLacking Enabled(true);

最终指令CREATE_TABLE = “CREATE TABLE FI NOT EXISTS details1 (“+ “ID INTEERT main keyAUTOINCREMENT”,+“First TEXT,”+“Lastname TEXT,”+“Username TEXT,”+“Pasword TEXT”, + “Monthlyincome TEXT”;

db1.execSQL(CREATE_TABLE);

问题回答
I think that u should try this

SQLiteDatabase myDB= null;
          String TableName = "db_entry";

          /* Create a Database. */
          try {
           myDB = this.openOrCreateDatabase("db_hw3", MODE_PRIVATE, null);
           myDB.execSQL("DROP TABLE IF EXISTS db_entry" );
           /* Create a Table in the Database. */
           myDB.execSQL("CREATE TABLE IF NOT EXISTS "
             + TableName
             + " (id INTEGER PRIMARY KEY AUTOINCREMENT, mb_text TEXT NOT NULL,ph_location TEXT);");

          }
          catch(Exception e) {
           Log.e("Error", "Error", e);
          } 




相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签