“未找到活动";在Android中 [英] "Activity not found" in Android

查看:132
本文介绍了“未找到活动";在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在eclipse中使用navigation-drawer模板来做一个简单的Android应用程序. 我在片段方面遇到了麻烦. 我在清单中声明了一个称为PresenceLog Fragment的片段,但是当我在MainActivity中调用它时,日志仍然显示

I am using the navigation-drawer template in eclipse to do a simple Android application. I have some trouble with fragment. I declared a fragment called PresenceLog Fragment in manifest but when I called it in MainActivity, the log still says that

03-23 13:54:50.817: E/AndroidRuntime(16750): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.singtel.ricecooker/com.singtel.ricecooker.PresenceLogFragment}; have you declared this activity in your AndroidManifest.xml?

这是我的清单

Here is my manifest

这是我的片段类

public class PresenceLogFragment extends Fragment{
private TextView myText = null;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    return inflater.inflate(R.layout.presence_log, null);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    ArrayList<String> userList = null;
    RiceServerRequest newRequest = new RiceServerRequest();
    //newRequest.getRequestInfo(this);

}

public void updateUserList(ArrayList<String> userList){
    LinearLayout lView = (LinearLayout) getView().findViewById (R.layout.presence_log);
    //LinearLayout ll = (LinearLayout)fragment.getView().findViewById(R.id.commentFragmentLayout);

    for (int i = 0; i < userList.size();i++){
        myText = new TextView(getActivity());
        myText.setText(userList.get(i));
        lView.addView(myText);
    }
    //setContentView(lView);
}

这是我的MainActivity

Here is my MainActivity

private void launchPresenceLog(){
    Intent intent = new Intent(this,PresenceLogFragment.class);
    startActivity(intent);
}

如果您知道我的代码有什么问题,那就太好了.另外,由于我是Android编程的新手,所以如果您可以建议一些在线课程,我将不胜感激.

It would be great if you know what is wrong with my code. Also, since I am new to Android programming, I would appreciate it if you could suggest some online courses.

推荐答案

您已经创建了一个Fragment,所以您不能像Activity那样调用它. 您需要用片段替换容器视图,正确地替换为FrameLayout.

You have created a Fragment so you could not call it like a Activity. You need to replace a container view, properly an FrameLayout with your Fragment.

getSupportFragmentManager()
  .beginTransaction()
  .replace(R.id.content_frame, new PresenceLogFragment())
  .commit();

这篇关于“未找到活动";在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆