首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android中的“活动找不到”

Android中的“活动找不到”
EN

Stack Overflow用户
提问于 2015-03-23 12:32:25
回答 8查看 3.7K关注 0票数 1

我在eclipse中使用navigation-drawer模板来做一个简单的安卓应用程序。我在碎片问题上有点麻烦。我在清单中声明了一个名为PresenceLog片段的片段,但是当我在MainActivity中调用它时,日志仍然说

代码语言:javascript
复制
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?

这是我的舱单

这是我的片段类

代码语言:javascript
复制
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

代码语言:javascript
复制
private void launchPresenceLog(){
    Intent intent = new Intent(this,PresenceLogFragment.class);
    startActivity(intent);
}

如果你知道我的代码有什么问题,那就太好了。另外,由于我是Android程序新手,如果你能推荐一些在线课程的话,我会很感激的。

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2015-03-23 12:46:34

您已经创建了一个片段,因此不能将其称为活动。您需要用片段替换容器视图,适当地替换为FrameLayout。

代码语言:javascript
复制
getSupportFragmentManager()
  .beginTransaction()
  .replace(R.id.content_frame, new PresenceLogFragment())
  .commit();
票数 2
EN

Stack Overflow用户

发布于 2015-03-23 12:50:48

你不能通过意图加载碎片。您必须使用片段管理器这样做:

代码语言:javascript
复制
Fragment fragment = new PresenceLogFragment(MainActivity.this);
FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();                
            ft.replace(R.id.yourFragmentContainer, fragment).commit();
票数 1
EN

Stack Overflow用户

发布于 2015-03-23 12:34:27

您在AndroidManifest.xml中声明了此活动吗?

查看清单,看看是否有注册了活动的<activity>元素。如果不是,再加一个。

看看这里:http://developer.android.com/guide/topics/manifest/activity-element.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29210295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档