我创建了与android数据库相关的预测。
它仅适用于GENYMOTION模拟器。 但是当我在移动设备上安装它时
android版本是5.0所以它显示错误是“0请求,大小为0”。 它也不适用于android emultor。
它只适用于genymotion模拟器。
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
usernamee=user.getText().toString();
userpass=pasword.getText().toString();
DatabaseOperations DOP=new DatabaseOperations(CTX);
Cursor CR=DOP.getInformation(DOP);
CR.moveToFirst();
boolean loginstatus=false;
String NAME="";
if(user.getText().toString().trim().length()==0||
pasword.getText().toString().trim().length()==0)
{
Toast.makeText(getBaseContext(), "Fields are empty Please enter
user name and password", Toast.LENGTH_LONG).show();
}
else{
try{
do{
if(usernamee.equals(CR.getString(0))&&
(userpass.equals(CR.getString(1))))
{
loginstatus=true;
NAME=CR.getString(0);
}
}
while(CR.moveToNext());
if(loginstatus)
{
Toast.makeText(getBaseContext(), "Log in Successed",
Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getBaseContext(), "Log in failed invalid user
name OR password or no record found", Toast.LENGTH_LONG).show();
}
}
}
当我点击上面的登录按钮时,它只适用于genymotion模拟器。 但是当我在安装了应用程序的移动设备中按下此登录按钮时。 它不起作用显示错误是索引0请求大小为0。 并在Android模拟器上也显示此错误。
日志猫是
08-29 13:29:35.978: I/Choreographer(1339): Skipped 93 frames! The
application may be doing too much work on its main thread.
08-29 13:29:36.956: I/Choreographer(1339): Skipped 43 frames! The
application may be doing too much work on its main thread.
08-29 13:29:37.498: I/Choreographer(1339): Skipped 43 frames! The
application may be doing too much work on its main thread.
08-29 13:29:53.498: D/InputEventConsistencyVerifier(1339): KeyEvent:
ACTION_UP but key was not down.
08-29 13:29:53.498: D/InputEventConsistencyVerifier(1339): in
android.widget.EditText{4178dba0 VFED..CL .F....I. 0,127-320,167
#7f080009 app:id/register_paswd}
08-29 13:29:53.498: D/InputEventConsistencyVerifier(1339): in
android.widget.EditText{4178dba0 VFED..CL .F....I. 0,127-320,167
#7f080009 app:id/register_paswd}
08-29 13:29:53.498: D/InputEventConsistencyVerifier(1339): 0: sent at
17891468000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB,
scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=17891468,
downTime=17891295, deviceId=0, source=0x101 }
08-29 13:29:53.498: D/InputEventConsistencyVerifier(1339): 0: sent at
17891468000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB,
scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=17891468,
downTime=17891295, deviceId=0, source=0x101 }
08-29 13:29:59.698: W/dalvikvm(1339): threadid=1: thread exiting with
uncaught exception (group=0x414c4700)
08-29 13:29:59.718: E/AndroidRuntime(1339): FATAL EXCEPTION: main
08-29 13:29:59.718: E/AndroidRuntime(1339):
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a
size of 0
08-29 13:29:59.718: E/AndroidRuntime(1339): at
android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
08-29 13:29:59.718: E/AndroidRuntime(1339
08-29 13:29:59.718:
ndowedCursor.java:50) 08-29 13:29:59.718:E / AndroidRuntime(1339):at com.example.student_record.Setting $ 2.onClick(Setting.java:149) 08-29 13:29:59.718:E / AndroidRuntime(1339):在android.view.View.performClick(View.java:4240) 08-29 13:29:59.718:E / AndroidRuntime(1339):在android.view.View $ PerformClick.run(View.java:17721) 08-29 13:29:59.718:E / AndroidRuntime(1339):在android.os.Handler.handleCallback(Handler.java:730) 08-29 13:29:59.718:E / AndroidRuntime(1339):在android.os.Handler.dispatchMessage(Handler.java:92) 08-29 13:29:59.718:E / AndroidRuntime(1339):在android.os.Looper.loop(Looper.java:137) 08-29 13:29:59.718:E / AndroidRuntime(1339):在android.app.ActivityThread.main(ActivityThread.java:5103) 08-29 13:29:59.718:E / AndroidRuntime(1339):at java.lang.reflect.Method.invokeNative(Native Method)
08-29 13:29:59.718: E/AndroidRuntime(1339): at
java.lang.reflect.Method.invoke(Method.java:525)
08-29 13:29:59.718: E/AndroidRuntime(1339): at
com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
08-29 13:29:59.718: E/AndroidRuntime(1339): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-29 13:29:59.718: E/AndroidRuntime(1339): at
dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
当你调用.moveToFirst()时,你的光标没有报告任何数据并且崩溃。在尝试使用游标之前,您应该检查它是否为null。