0

我是 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

对此有什么想法吗?

4

5 回答 5

0

正如您的 logcat 所说:

 android.content.ActivityNotFoundException: Unable to find explicit activity class 
{com.droid/com.droid.DocLogin}; have you declared this activity in your AndroidManifest.xml?

原因

您没有在清单文件中声明 com.droid.DocLogin 。

在清单中声明此活动将删除此异常。

// 你还有一个例外,那就是:

java.lang.ClassCastException: com.droid.DocLogin cannot be cast to android.app.Activity 

这是因为DocLogin是一个片段而不是一个活动,您也可以使用 getactivity() 作为片段的上下文。

于 2014-06-23T06:28:55.493 回答
0

ActivitynotFound 异常是因为 AndroidManifest.xml 文件中没有活动声明。

我认为您的 Activity 类是 DocProfile。确保它扩展了 FragmentActivity 并将 DocLogin 片段添加到 DocProfile Activty。

于 2014-06-23T06:22:00.750 回答
0

DocLogin是 Fragment 不是Activity.

添加 DocLogin然后在文件FragmentActivity声明ActivityAndroidManifest.xml

于 2014-06-23T06:15:20.023 回答
0

显示 ActivityNotFound 异常是因为它找不到所述活动。代替您创建的类,创建一个相同的 Android Activity 并在 Android Manifest 中声明它。

于 2014-06-23T06:16:47.467 回答
0

DocLogin 没有扩展活动。所以删除片段并扩展活动

如果您希望 DocLogin 扩展片段,则再创建一个活动并将视图添加到由 DocLogin 返回的该活动,如下所示。

公共类 MainActivity 扩展 Activity{

DocLogin doclogin;

//In oncreate
 doclogin = new DocLogin();
 setcontentview(doclogin);

}

请在您的 AndroidManifest.xml 中添加您的活动。

当你想创建新的活动时,你应该在你的 AndroidManifest.xml 中注册它。

于 2014-06-23T06:25:08.773 回答