我是Android编程的新手,但似乎我找不到我的错误我需要你的帮助
每次我登录并点击按钮btnLogin
app停止。
登录类
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
有关于此的任何想法吗?
答案 0 :(得分:0)
DocLogin
片段不是Activity
。
将DocLogin Fragment
添加到Activity
,然后在Activity
文件中声明AndroidManifest.xml
答案 1 :(得分:0)
显示ActivityNotFound异常,因为它无法找到所述活动。而不是您创建的类,创建相同的Android Activity并在Android Manifest中声明它。
答案 2 :(得分:0)
ActivitynotFound异常是因为AndroidManifest.xml文件中没有活动声明。
我认为您的Activity类是DocProfile。确保它扩展FragmentActivity并将DocLogin片段添加到DocProfile Activty。
答案 3 :(得分:0)
DocLogin不会扩展活动。所以删除片段并扩展活动
如果您希望DocLogin扩展片段,则再创建一个活动,并将视图添加到由DocLogin返回的活动,如下所示。
公共类MainActivity扩展了Activity {
DocLogin doclogin;
//In oncreate
doclogin = new DocLogin();
setcontentview(doclogin);
}
请在AndroidManifest.xml中添加您的活动。
如果您想进行新活动,请在AndroidManifest.xml中注册。
答案 4 :(得分: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()作为片段的上下文。