Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 找不到片段MyFragment的id 0x的视图_Java_Android_Android Layout_Android Fragments_Crash - Fatal编程技术网

Java 找不到片段MyFragment的id 0x的视图

Java 找不到片段MyFragment的id 0x的视图,java,android,android-layout,android-fragments,crash,Java,Android,Android Layout,Android Fragments,Crash,我在调用FragmentManager中的新片段时遇到问题。 当我尝试调用主活动中的片段时,我收到此日志,我不知道为什么: Process: com.robertot.timereport, PID: 31255 java.lang.IllegalArgumentException: No view found for id 0x7f07000a (com.robertot.timereport:id/content_frame) for fragment MyFragment{64c0

我在调用FragmentManager中的新片段时遇到问题。 当我尝试调用主活动中的片段时,我收到此日志,我不知道为什么:

Process: com.robertot.timereport, PID: 31255
    java.lang.IllegalArgumentException: No view found for id 0x7f07000a (com.robertot.timereport:id/content_frame) for fragment MyFragment{64c07710 #0 id=0x7f07000a}
这是我的主要活动课:

public class MainActivity extends FragmentActivity
{
     @Override
     protected void onCreate(Bundle savedInstanceState) 
     {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //...

     }

     private void LoadFragment(int position)
     {
        Fragment frgm = null;
        FragmentManager fm = getSupportFragmentManager();

        switch(position)
        {
            case 1:
                frgm = new MyFragment();
                fragmentTag = "newjob";
                break;
        }

        fm.beginTransaction()
               .replace(R.id.content_frame, frgm, fragmentTag)   // CRASH HERE
                .commit();
    }
}
这是我的活动\u主xml:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/content_frame">
</FrameLayout>
我做错了什么


谢谢你的支持

这是创建项目时的android示例:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

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

}
activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.asdsd.MainActivity"
    tools:ignore="MergeRootFrame" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.asdsd.MainActivity$PlaceholderFragment" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
fragment_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.asdsd.MainActivity"
    tools:ignore="MergeRootFrame" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.asdsd.MainActivity$PlaceholderFragment" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

这肯定会奏效,我希望它能帮助您在R.java中找到解决方案,并搜索这个id:0x7f07000a,它是什么?R.java中有。公共静态最终整数内容\u帧=0x7f07000a;你能展示你的MyFragment类吗?我编辑了主帖…所以,我不认为这是MyFragment的问题…但我不知道可能名称不匹配,或者尝试重新加载项目?不,不起作用…我没有希望。。。我正在尝试所有的解决方案!看我最后的机会:这是荒谬的…不起作用…所以,谢谢你。我感谢你的帮助