2016-09-24 100 views
0

我在Android編程中是begginer,我試圖使登錄功能。這個系統將被兩個用戶admin和用戶訪問。管理員只需輸入用戶名和密碼的「admin」即可訪問系統。但是,用戶在登錄系統之前需要註冊他們的賬戶。嘗試登錄系統時無法檢索數據(Android Studio)

我試圖找到錯誤但仍然不知道錯誤發生。請幫我解決錯誤。謝謝。

DatabaseOperations.java

public Cursor getInformation(DatabaseOperations dob) 
{ 
    SQLiteDatabase database=dob.getReadableDatabase(); 
    String[] columns={TableInfo.USERNAME,TableInfo.USERPASS}; 
    Cursor cr=database.query(TableInfo.TABLE_NAME,columns,null,null,null,null,null); 
    return cr; 
} 

MainActivity.java

public void onClick(View view) 
Toast.makeText(getBaseContext(), "Please wait....", Toast.LENGTH_LONG).show(); 
    txtusername = Username.getText().toString(); 
    txtpassword = Password.getText().toString(); 
    DatabaseOperations dop = new DatabaseOperations(this, null, null, 1); 
    Cursor CR = dop.getInformation(dop); 
    CR.moveToFirst(); 
    boolean login_status = false; 
    String NAME = ""; 
    if (txtusername.equals("Admin") && (txtpassword).equals("Admin")) { 
     Intent in = new Intent(MainActivity.this, AdminMenu.class); 
     startActivity(in); 
    } else { 
     do { 
      if (txtusername.equals(CR.getString(0)) && (txtpassword.equals(CR.getString(1)))) { 
       login_status = true; 
       NAME = CR.getString(0); 
      } 
     } while (CR.moveToNext()); 
     if (login_status) { 
      Toast.makeText(getBaseContext(), "Login Success....\n Welcome " + NAME, Toast.LENGTH_LONG).show(); 
      Intent i=new Intent(MainActivity.this,UserMenu.class); 
      Bundle bundle=new Bundle(); 
      bundle.putString("username",NAME); 
      i.putExtras(bundle); 
      startActivity(i); 
      finish(); 
     } else { 
      Toast.makeText(getBaseContext(), "Login Failed...", Toast.LENGTH_LONG).show(); 
      Intent i = new Intent(); 
      Bundle bundle=new Bundle(); 
      bundle.putString("username",NAME); 
      i.putExtras(bundle); 
      startActivity(i); 
      finish(); 
     } 
    } 
} 

這是錯誤...

E/AndroidRuntime: FATAL EXCEPTION: main 
       Process: com.google.mobile_flexi_parking, PID: 6777 
       java.lang.IllegalStateException: Could not execute method for android:onClick 
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) 
        at android.view.View.performClick(View.java:5198) 
        at android.view.View$PerformClick.run(View.java:21147) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
       Caused by: java.lang.reflect.InvocationTargetException 
        at java.lang.reflect.Method.invoke(Native Method) 
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
        at android.view.View.performClick(View.java:5198)  
        at android.view.View$PerformClick.run(View.java:21147)  
        at android.os.Handler.handleCallback(Handler.java:739)  
        at android.os.Handler.dispatchMessage(Handler.java:95)  
        at android.os.Looper.loop(Looper.java:148)  
        at android.app.ActivityThread.main(ActivityThread.java:5417)  
        at java.lang.reflect.Method.invoke(Native Method)  
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
       Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { (has extras) } 
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798) 
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512) 
        at android.app.Activity.startActivityForResult(Activity.java:3917) 
        at android.app.Activity.startActivityForResult(Activity.java:3877) 
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842) 
        at android.app.Activity.startActivity(Activity.java:4200) 
        at android.app.Activity.startActivity(Activity.java:4168) 
        at com.google.mobile_flexi_parking.MainActivity.onclickLogin(MainActivity.java:67) 
        at java.lang.reflect.Method.invoke(Native Method)  
        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)  
        at android.view.View.performClick(View.java:5198)  
        at android.view.View$PerformClick.run(View.java:21147)  
        at android.os.Handler.handleCallback(Handler.java:739)  
        at android.os.Handler.dispatchMessage(Handler.java:95)  
        at android.os.Looper.loop(Looper.java:148)  
        at android.app.ActivityThread.main(ActivityThread.java:5417)  
        at java.lang.reflect.Method.invoke(Native Method)  
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
+2

檢查您在menifest文件中的所有活動....... – sushildlh

+0

'原因:android.content.ActivityNotFoundException:未找到處理Intent的活動。檢查您的所有活動是否在Manifest中聲明。 – Vikrant

+0

'引起:android.content.ActivityNotFoundException:找不到處理意圖的活動。在你登錄失敗的時候,你並沒有定義要跳轉到的類。 in Intent i = new Intent();'。它應該像'Intent i = new Intent(MainActivity.this,YOURCLASS.class)'; –

回答

0

在你的其他部分,你有空白intent這不點任意activity

Intent i = new Intent(); 

我認爲這是造成錯誤。

+0

真棒......它的工作原理。謝謝〜 – Jayson

+0

@Jayson請接受我的答案,如果它幫助你。 :) – Nikhil

+0

好~~完成~~~~:D – Jayson