获取片段错误

时间:2017-03-01 19:25:27

标签: android android-studio android-fragments

我是Android工作室和编程的新手,我已尝试过许多视频教程,并在本网站上阅读已回答的问题,但无法找到答案,我们将不胜感激。

错误:java.lang.IllegalArgumentException:找不到片段FragOne {8f6227a#0 id = 0x7f0d0084}

的id 0x7f0d0084(com.example.hotrod.hotrodsapp:id / content_frame)的视图

当我尝试从模拟器中的导航器打开页面时,我使用导航抽屉模板并收到此错误。

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

这是我的fraone的代码 -

public class FragOne extends android.app.Fragment {

View myView;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myView = inflater.inflate(R.layout.layout1, container ,false);
    return myView;
}

}

0 个答案:

没有答案