Android java.lang.IllegalArgumentException:找不到id为0x7f0c005b的视图

Android java.lang.IllegalArgumentException:找不到id为0x7f0c005b的视图,android,android-fragments,Android,Android Fragments,我得到的Android运行时异常如下 java.lang.IllegalArgumentException:找不到id为0x7f0c005b的视图 用于android for navigation应用程序中的片段活动。我在Fragment类中添加了onDestroy(),在此之前,我得到了OutOfMemory异常,现在我得到了刷新后得到的视图未找到 我的代码如下所示 public class VerticesFreehandFragment extends Fragment {

我得到的Android运行时异常如下

java.lang.IllegalArgumentException:找不到id为0x7f0c005b的视图

用于android for navigation应用程序中的片段活动。我在Fragment类中添加了
onDestroy()
,在此之前,我得到了
OutOfMemory异常
,现在我得到了刷新后得到的
视图未找到

我的代码如下所示

    public class VerticesFreehandFragment extends Fragment {

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

        DatabaseHandler dbHandler = new DatabaseHandler(getActivity());
        try {
            dbHandler.createDataBase();
        } catch (IOException ioe) {
            throw new Error("Unable to create database");
        }

        try {
            dbHandler.openDataBase();
            dbHandler.close();
        }catch(SQLException sqle){
            throw sqle;
        }

        final View rootView = inflater.inflate(R.layout.extension_freehand_fragment, container, false);

        final VerticesPoints imageView = (VerticesPoints)rootView.findViewById(R.id.imageView);
        imageView.setImage(ImageSource.resource(R.drawable.floor_plan));

        final VerticesPointsSecondFloor image = (VerticesPointsSecondFloor)rootView.findViewById(R.id.image);
        image.setImage(ImageSource.resource(R.drawable.floor_plan2));

        PointF center = new PointF(1226, 816);
        imageView.setScaleAndCenter(0.8f, center);
        image.setScaleAndCenter(0.8f, center);

        FloatingActionMenu actionMenu = (FloatingActionMenu) rootView.findViewById(R.id.menu);
        FloatingActionButton floor1 = (FloatingActionButton) rootView.findViewById(R.id.floor1);
        FloatingActionButton floor2 = (FloatingActionButton) rootView.findViewById(R.id.floor2);

        floor1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Floor1", Toast.LENGTH_SHORT).show();
                imageView.setVisibility(View.VISIBLE);
                image.setVisibility(View.INVISIBLE);
            }
        });

        floor2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Floor2", Toast.LENGTH_SHORT).show();
                imageView.setVisibility(View.INVISIBLE);
                image.setVisibility(View.VISIBLE);
            }
        });

        return rootView;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        onDestroyView(getActivity());
    }

    public static void onDestroyView(Activity activity) {
        View rootView = null;

        try {
            rootView = ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
        } catch (Exception e) {
            Log.e("Cannot find root view", "activity");
        }

        if (rootView != null) {
            Log.d("unbindDrawables", "activity, rootView");
            unbindDrawables(rootView);
        }
    }

    /**
     * Utility method to unbind drawables when an activity is destroyed.  This
     * ensures the drawables can be garbage collected.
     */
    public static void unbindDrawables(View view) {
        if (view.getBackground() != null) {
            view.getBackground().setCallback(null);
        }

        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                unbindDrawables(((ViewGroup) view).getChildAt(i));
            }

            try {
                // AdapterView objects do not support the removeAllViews method
                if (!(view instanceof AdapterView)) {
                    ((ViewGroup) view).removeAllViews();
                }
            } catch (Exception e) {
                Log.w("Ignore Exception", e);
            }
        }
    }

}
公共类VerticesFreehandFragment扩展了片段{
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
DatabaseHandler dbHandler=新的DatabaseHandler(getActivity());
试一试{
dbHandler.createDataBase();
}捕获(ioe异常ioe){
抛出新错误(“无法创建数据库”);
}
试一试{
dbHandler.openDataBase();
dbHandler.close();
}捕获(SQLException sqle){
抛出sqle;
}
最终视图根视图=充气机。充气(R.layout.extension\u徒手\u碎片,容器,错误);
最终VerticesPoints imageView=(VerticesPoints)rootView.findViewById(R.id.imageView);
设置图像(ImageSource.resource(R.drawable.floor_plan));
最终VerticesPointsSecondFloor图像=(VerticesPointsSecondFloor)rootView.findViewById(R.id.image);
image.setImage(ImageSource.resource(R.drawable.floor_plan2));
点F中心=新点F(1226816);
图像视图。设置刻度和中心(0.8f,中心);
图像。设置刻度和中心(0.8f,中心);
FloatingActionMenu actionMenu=(FloatingActionMenu)rootView.findViewById(R.id.menu);
FloatingActionButton floor1=(FloatingActionButton)rootView.findViewById(R.id.floor1);
FloatingActionButton floor2=(FloatingActionButton)rootView.findViewById(R.id.floor2);
floor1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(getActivity(),“Floor1”,Toast.LENGTH_SHORT.show();
设置可见性(View.VISIBLE);
image.setVisibility(View.INVISIBLE);
}
});
floor2.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(getActivity(),“Floor2”,Toast.LENGTH_SHORT.show();
imageView.setVisibility(视图.不可见);
image.setVisibility(View.VISIBLE);
}
});
返回rootView;
}
@凌驾
公共空间{
super.ondestory();
onDestroyView(getActivity());
}
公共静态void onDestroyView(活动){
视图rootView=null;
试一试{
rootView=((ViewGroup)activity.findviewbyd(android.R.id.content)).getChildAt(0);
}捕获(例外e){
Log.e(“找不到根视图”、“活动”);
}
if(rootView!=null){
Log.d(“未绑定的可提取项”、“活动、根视图”);
不可绑定的绘图(rootView);
}
}
/**
*当活动被销毁时解除可提取项绑定的实用方法
*确保可抽出物可以被垃圾回收。
*/
公共静态无效不可绑定绘图(视图){
if(view.getBackground()!=null){
view.getBackground().setCallback(null);
}
if(视图组的视图实例){
对于(int i=0;i<((视图组)视图)。getChildCount();i++){
未绑定的Drawables(((视图组)视图).getChildAt(i));
}
试一试{
//AdapterView对象不支持removeAllViews方法
如果(!(查看AdapterView实例)){
((视图组)视图);
}
}捕获(例外e){
Log.w(“忽略异常”,e);
}
}
}
}
我的上述clas的XML文件是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.cosmonet.murali.floormarker.Views.VerticesPoints
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:visibility="visible"/>

<com.cosmonet.murali.floormarker.Views.VerticesPointsSecondFloor
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:visibility="invisible"/>

<com.github.clans.fab.FloatingActionMenu
    android:id="@+id/menu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    fab:menu_fab_size="normal"
    fab:menu_labels_style="@style/menu_labels_style"
    fab:menu_labels_position="left"
    fab:menu_icon="@drawable/ic_up_arrow"
    fab:menu_openDirection="up"
    fab:menu_backgroundColor="@android:color/transparent">

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/floor2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_fab_star"
        fab:fab_size="mini"
        fab:fab_label="Second Floor" />

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/floor1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_floor1"
        fab:fab_size="mini"
        fab:fab_label="First Floor" />

</com.github.clans.fab.FloatingActionMenu>


提前谢谢

请发布
R.layout.extension\u freehand\u fragment
您正在使函数保持静态,因此它将首先执行,因此在unbindDrawables中它将调用removeAllViews。@Boss me为此添加了XML文件class@Rubanraj正如u所说,我尝试删除静态类,然后也删除了相同的问题—它删除了所有视图—这种类型的问题是通过XML生成的,因此,请正确检查您的XML文件。请发布
R.layout.extension\u freehand\u fragment
您将函数设置为静态,因此它将首先执行,因此在unbindDrawables中它将调用removeAllViews。@Boss me为此添加了XML文件class@Rubanraj正如你所说的,我尝试删除静态类,然后也删除了相同的问题,它删除了所有视图。这种类型的问题是通过XML生成的,所以请正确检查XML文件。