2014-11-01 69 views
0

我正在嘗試在ma應用程序中進行註冊活動我想在用戶輸入學生ID時查看學生ID是否在數據庫中如果有註冊if不 其表示,其錯誤....所以我有錯誤...由logcat的比較來自sqlite數據庫的數據N已插入的數據

 EditText st_id , st_pass, Pass_again; 
String student_id ,pass_ag ,pass; 
Button regs, cancel_reg; 
    Context cxt,cxt2; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.registor); 
     st_id=(EditText)findViewById(R.id.st_id); 
     st_pass=(EditText)findViewById(R.id.st_pass); 
     Pass_again=(EditText)findViewById(R.id.pass_again); 
     cxt=this; 
     regs=(Button)findViewById (R.id.regs) ; 
     cancel_reg=(Button) findViewById(R.id.cancel_reg); 
     regs.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       student_id=st_id.getText().toString(); 
       pass=st_pass.getText().toString(); 
       pass_ag=Pass_again.getText().toString(); 
       Getdata info = new Getdata (cxt); 
       info.open(); 
       String data=info.getdata(); 
      Cursor CR=info.getdata(cxt2); 
       info.close(); 
       CR.moveToFirst(); 



       /*if(!(pass.equals(pass_ag) && (student_id.equals(CR.getString(0))))) 
       { 
        Toast.makeText(getBaseContext(), "Password not match /n or student id not found", Toast.LENGTH_LONG).show(); 
        st_id.setText(""); 
        st_pass.setText(""); 
        Pass_again.setText(""); 

       } 
       else 
       { 
        DataBaseopretions db =new DataBaseopretions(cxt); 
      db.putinformation(db, student_id, pass , pass_ag); 
      Toast.makeText(getBaseContext(), "Registrtion success", Toast.LENGTH_LONG).show(); 
      finish(); 
       } 

      } 
     });*/ 
       CR.moveToFirst(); 
       boolean loginstatus=false; 
       String student = ""; 
       do{ 
        if(!(pass.equals(pass_ag) && (student_id.equals(CR.getString(0))))){ 
         loginstatus=true; 
         student=CR.getString(0); 
        } 

       }while(CR.moveToNext()); 
        if(loginstatus) 
        { 
         Toast.makeText(getBaseContext(), "Rigstretion sucsess--- \n Welcome"+ student, Toast.LENGTH_LONG).show(); 
         Intent i= new Intent(Rigstretion.this ,Student_pag.class); 
         startActivity(i); 
        } 
        else 
        { 
         Toast.makeText(getBaseContext(), "Rigstretion failed--- wrong student id or password doesn't match", Toast.LENGTH_LONG).show(); 

         finish(); 
        } 
      } 
        }); 

     cancel_reg.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       student_id=" "; 
       pass=" "; 
       pass_ag=" "; 
       finish(); 
      } 
     }); 


    } 
} 

logcat的

11-01 18:54:51.204: E/AndroidRuntime(28496): FATAL EXCEPTION: main 
11-01 18:54:51.204: E/AndroidRuntime(28496): java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed. 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:196) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at za.example.drawer.Rigstretion$1.onClick(Rigstretion.java:43) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.view.View.performClick(View.java:4084) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.view.View$PerformClick.run(View.java:16966) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.os.Handler.handleCallback(Handler.java:615) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.os.Handler.dispatchMessage(Handler.java:92) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.os.Looper.loop(Looper.java:137) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at android.app.ActivityThread.main(ActivityThread.java:4745) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at java.lang.reflect.Method.invokeNative(Native Method) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at java.lang.reflect.Method.invoke(Method.java:511) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
11-01 18:54:51.204: E/AndroidRuntime(28496): at dalvik.system.NativeStart.main(Native Method) 
11-01 18:54:51.208: W/ActivityManager(325): Force finishing activity za.example.drawer/.Rigstretion 
11-01 18:54:51.256: E/SocketStream(111): readFully was waiting for 275772 bytes, got 49152 
11-01 18:54:51.260: E/SocketStream(111): readFully was waiting for 226620 bytes, got 49152 
11-01 18:54:51.260: E/SocketStream(111): readFully was waiting for 177468 bytes, got 49152 
11-01 18:54:51.264: E/SocketStream(111): readFully was waiting for 128316 bytes, got 16384 
11-01 18:54:51.276: W/audio_hw_primary(114): out_write() limiting sleep time 58911 to 39909 
11-01 18:54:51.776: W/ActivityManager(325): Activity pause timeout for ActivityRecord{5355d548 za.example.drawer/.Rigstretion} 
11-01 18:55:01.276: W/ActivityManager(325): Launch timeout has expired, giving up wake lock! 
11-01 18:55:01.780: W/ActivityManager(325): Activity idle timeout for ActivityRecord{5351228c za.example.drawer/.MainActivity} 

所以任何人都可以幫我下面 這個代碼???

+0

嘗試關閉你的'光標',當你在'do-while'後面使用它時。 – akodiakson 2014-11-01 19:16:17

回答

0
info.close(); //remove this line 
    CR.moveToFirst(); 

如果我正確理解你的代碼,你是因爲你試着做一些操作後關閉數據庫得到了異常。嘗試刪除info.close();並僅在完成操作後關閉數據庫。 (也許在do-while完成後,在你的情況)

+0

非常感謝你..它的作品^^ – marwa 2014-11-01 20:44:55