Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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 Logcat在使用SurfaceHolder覆盖碎片时抛出错误_Java_Android_Xml_Android Fragments_Surfaceholder - Fatal编程技术网

Java Logcat在使用SurfaceHolder覆盖碎片时抛出错误

Java Logcat在使用SurfaceHolder覆盖碎片时抛出错误,java,android,xml,android-fragments,surfaceholder,Java,Android,Xml,Android Fragments,Surfaceholder,我试图用cameraPreview实例覆盖片段。片段布局的根有一个xml标记您使用了错误的布局文件作为片段的根布局。在getView()中展开的布局文件应该是指定希望在片段内部看到的视图的文件,而不是片段本身 我相信布局充气机只能递归地走25步深 您应该添加false作为LayoutInflater.flate的第三个参数 并且CameraPreviewFragment不是上下文首先使用R.layout.CameraPreviewFragment进行膨胀,但是您创建的布局是fragmentRo

我试图用
cameraPreview
实例覆盖
片段
片段
布局的根有一个xml标记
您使用了错误的布局文件作为片段的根布局。在getView()中展开的布局文件应该是指定希望在片段内部看到的视图的文件,而不是片段本身

我相信布局充气机只能递归地走25步深


您应该添加
false
作为
LayoutInflater.flate
的第三个参数


并且
CameraPreviewFragment
不是
上下文

首先使用R.layout.CameraPreviewFragment进行膨胀,但是您创建的布局是fragmentRoot\u布局和

tools:context="com.example.fragmentwithcamerasurface.CameraPreviewFragment"  
CameraPreviewFragment不是上下文


嘿,检查有关工具的详细信息:context

ok,如果
CameraPreviewFragment
没有上下文,并且要从扩展surfaceholder的类实例化对象,您应该提供一个上下文,如何解决这个问题?@Amr no no,看看我的第一句话。ok,我将其修改为“View=inflater.inflate”(R.layout.camerapreviewfragment,null,false);“但是,很不幸,同样的错误发布了您的片段的布局文件。当我添加了“工具:上下文…”一行时,请参见上面发布的fragment_root和main activity_布局。”我认为这很重要。但是knw按照你的建议删除了它,但我收到了相同的错误!请你告诉我这行“工具:上下文…”何时开始有用吗?
tools:context
行不是罪魁祸首。@Troopers你真的复制粘贴了我的答案。@dcow供参考,当我在另一个选项卡中打开问题时,当时没有答案,所以我没有签出你的答案就回答了问题…..而且现在你已经编辑了布局文件so:D…..有了吗也在你面前(;
<?xml version="1.0" encoding="utf-8"?>
<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.fragmentwithcamerasurface.MainActivity"
tools:ignore="MergeRootFrame">
    <fragment
        android:name="com.example.fragmentwithcamerasurface.CameraPreviewFragment"
        android:id="@+id/fragment00ID"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </fragment>
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="MergeRootFrame"
android:background="#ffff00">

<!--logcat complains about this line-->
    <com.example.fragmentwithcamerasurface.CustomCameraView
    android:id="@+id/surfaceView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"/>
 05-28 09:34:13.670: E/AndroidRuntime(11327): java.lang.RuntimeException: Unable to  
 start activity   
 ainActivity}: android.view.InflateException: Binary XML file line #11: Error  
 inflating class com.example.fragmentwithcamerasurface.CustomCameraView
 05-28 09:34:13.670: E/AndroidRuntime(11327): java.lang.RuntimeException: Unable to 
 start activity  
 ainActivity}: android.view.InflateException: Binary XML file line #11: Error   
 inflating class com.example.fragmentwithcamerasurface.CustomCameraView
 05-28 09:34:13.670: E/AndroidRuntime(11327):   at  
tools:context="com.example.fragmentwithcamerasurface.CameraPreviewFragment"