我正在尝试fragment
用cameraPreview
实例覆盖一个。布局的根fragment
有一个 xml 标签<surfaceview
。当我运行应用程序时,它会崩溃并引发以下错误。知道为什么会这样吗?
Class_Extends_Fragment:
public class CameraPreviewFragment extends Fragment {
private CustomCameraView mCameraPreview = null;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mCameraPreview = new CustomCameraView(this.getActivity());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.camerapreviewfragment, null);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
SurfaceView sv = (SurfaceView) getView().findViewById(R.id.surfaceView);
}
MainActivity_layout:
<?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