我是 android 编程新手,但似乎找不到我的错误,我需要你的帮助
每次我登录并单击按钮btnLogin
应用程序都会停止。
登录类
public class DocLogin extends Fragment {
ImageView ivIcon;
TextView tvItemName, tvRegister;
EditText user, pass;
Button btnLogin;
SQLController dbcon;
SessionManager session;
public DocLogin() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.doc_log_in, container, false);
session = new SessionManager(getActivity());
dbcon = new SQLController(getActivity());
dbcon.open();
// Log in
user = (EditText) view.findViewById(R.id.etUser);
pass = (EditText) view.findViewById(R.id.etPassword);
btnLogin = (Button) view.findViewById(R.id.btnLogin);
// Sign up
tvRegister = (TextView) view.findViewById(R.id.tvRegDoc);
tvRegister.setMovementMethod(LinkMovementMethod.getInstance());
tvRegister.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, new DocReg());
ft.commit();
return false;
}
});
// btnLogin onClickListener
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
dbcon = new SQLController(getActivity());
dbcon.open();
Log.v("LoginDetails", user.getText().toString() + "../.."
+ pass.getText().toString());
Cursor cur = dbcon.getuser_information(user.getText()
.toString(), pass.getText().toString());
if (cur.getCount() != 0) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, new DocProfile());
ft.commit();
} else {
AlertDialog alertDialog = new AlertDialog.Builder(
getActivity()).create();
alertDialog.setTitle("Login Error");
alertDialog
.setMessage("Doctor Code and Password does not match");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
// dismiss dialog
}
});
alertDialog.show();
}
}
});
return view;
}
}
这是我得到的错误
06-23 14:11:16.483: E/Trace(4864): error opening trace file: No such file or directory (2)
06-23 14:11:27.783: E/AndroidRuntime(4864): FATAL EXCEPTION: main
06-23 14:11:27.783: E/AndroidRuntime(4864): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.droid/com.droid.DocLogin}; have you declared this activity in your AndroidManifest.xml?
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.Activity.startActivityForResult(Activity.java:3351)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.Activity.startActivityForResult(Activity.java:3312)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.Activity.startActivity(Activity.java:3522)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.Activity.startActivity(Activity.java:3490)
06-23 14:11:27.783: E/AndroidRuntime(4864): at com.droid.SessionManager.checkLogin(SessionManager.java:41)
06-23 14:11:27.783: E/AndroidRuntime(4864): at com.droid.DocProfile.onCreateView(DocProfile.java:43)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.BackStackRecord.run(BackStackRecord.java:635)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.os.Handler.handleCallback(Handler.java:615)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.os.Handler.dispatchMessage(Handler.java:92)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.os.Looper.loop(Looper.java:137)
06-23 14:11:27.783: E/AndroidRuntime(4864): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-23 14:11:27.783: E/AndroidRuntime(4864): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 14:11:27.783: E/AndroidRuntime(4864): at java.lang.reflect.Method.invoke(Method.java:511)
06-23 14:11:27.783: E/AndroidRuntime(4864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-23 14:11:27.783: E/AndroidRuntime(4864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-23 14:11:27.783: E/AndroidRuntime(4864): at dalvik.system.NativeStart.main(Native Method)
但是在声明DocLogin
类之后AndroidManifest
这是错误
06-23 14:09:53.463: E/AndroidRuntime(4791): FATAL EXCEPTION: main
06-23 14:09:53.463: E/AndroidRuntime(4791): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.droid/com.droid.DocLogin}: java.lang.ClassCastException: com.droid.DocLogin cannot be cast to android.app.Activity
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.ActivityThread.access$600(ActivityThread.java:130)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.os.Looper.loop(Looper.java:137)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-23 14:09:53.463: E/AndroidRuntime(4791): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 14:09:53.463: E/AndroidRuntime(4791): at java.lang.reflect.Method.invoke(Method.java:511)
06-23 14:09:53.463: E/AndroidRuntime(4791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-23 14:09:53.463: E/AndroidRuntime(4791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-23 14:09:53.463: E/AndroidRuntime(4791): at dalvik.system.NativeStart.main(Native Method)
06-23 14:09:53.463: E/AndroidRuntime(4791): Caused by: java.lang.ClassCastException: com.droid.DocLogin cannot be cast to android.app.Activity
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
06-23 14:09:53.463: E/AndroidRuntime(4791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
06-23 14:09:53.463: E/AndroidRuntime(4791): ... 11 more
对此有什么想法吗?