수업 연장시 팽창 오류
GhostSurfaceCameraView
확장 되는 사용자 정의보기를 만들려고합니다 SurfaceView
. 여기 내 클래스 정의 파일이 있습니다
GhostSurfaceCameraView.java
:
public class GhostSurfaceCameraView extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
GhostSurfaceCameraView(Context context) {
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where to draw.
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
// TODO: add more exception handling logic here
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
parameters.set("orientation", "portrait");
// parameters.setRotation(90); // API 5+
mCamera.setParameters(parameters);
mCamera.startPreview();
}
}
그리고 이것은 내 ghostviewscreen.xml에 있습니다.
<com.alpenglow.androcap.GhostSurfaceCameraView android:id="@+id/ghostview_cameraview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
이제 내가 만든 활동에서 :
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.ghostviewscreen);
}
}
때 setContentView()
호출되는 예외가 발생합니다 :
Binary XML file 09-17 22:47:01.958: ERROR/ERROR(337):
ERROR IN CODE:
android.view.InflateException: Binary
XML file line #14: Error inflating
class
com.alpenglow.androcap.GhostSurfaceCameraView
왜 내가이 오류가 발생했는지 말해 줄 수 있습니까? 감사.
왜 이것이 작동하지 않는지 알았습니다. 두 개의 매개 변수 'Context, AttributeSet'에 대한 생성자를 제공해야 할 때 하나의 매개 변수 'context'의 경우에만 생성자를 제공하고있었습니다. 또한 생성자에게 공개 액세스 권한을 부여해야했습니다. 여기 내 수정이 있습니다.
public class GhostSurfaceCameraView extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
public GhostSurfaceCameraView(Context context)
{
super(context);
init();
}
public GhostSurfaceCameraView(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}
public GhostSurfaceCameraView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
@Tim-두 생성자 모두 필요하지 않으며 ViewClassName(Context context, AttributeSet attrs )
생성자 만 필요합니다. 나는 몇 시간과 몇 시간을 낭비한 후에 고통스러운 방법을 발견했습니다.
I am very new to Android development, but I am making a wild guess here, that it maybe due to the fact that since we are adding the custom View
class in the XML file, we are setting several attributes to it in the XML, which needs to be processed at the time of instantiation. Someone far more knowledgeable than me will be able to shed clearer light on this matter though.
Another possible cause of the "Error inflating class" message could be misspelling the full package name where it's specified in XML:
<com.alpenglow.androcap.GhostSurfaceCameraView android:id="@+id/ghostview_cameraview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Opening your layout XML file in the Eclipse XML editor should highlight this problem.
It's important to write full class path in the xml. I got 'Error inflating class' when only subclass's name was written in.
I had this error plaguing me for the past few hours. Turns out, I had added the custom view lib as a module in Android Studio, but I had neglected to add it as a dependency in app's build.gradle
.
dependencies {
...
compile project(':gifview')
}
fwiw, I received this error due to some custom initialization within the constructor attempting to access a null object.
I had the same problem extending a TextEdit. For me the mistake was I did non add "public" to the constructor. In my case it works even if I define only one constructor, the one with arguments Context
and AttributeSet
. The wired thing is that the bug reveals itself only when I build an APK (singed or not) and I transfer it to the devices. When the application is run via AndroidStudio -> RunApp on a USB connected device the app works.
in my case I added such cyclic resource:
<drawable name="above_shadow">@drawable/above_shadow</drawable>
then changed to
<drawable name="some_name">@drawable/other_name</drawable>
and it worked
In my case, I copied my class from somewhere else and didn't notice right away that it was an abstract
class. You can't inflate abstract classes.
참고URL : https://stackoverflow.com/questions/3739661/error-inflating-when-extending-a-class
'Programming' 카테고리의 다른 글
사전 및 기본값 (0) | 2020.05.14 |
---|---|
플라스크의 URL로 리디렉션 (0) | 2020.05.14 |
Java 및 .NET에서 문자열을 변경할 수없는 이유는 무엇입니까? (0) | 2020.05.14 |
파이썬에서 함수에서 두 값을 어떻게 반환 할 수 있습니까? (0) | 2020.05.14 |
jQuery를 사용하여 텍스트를 클라이언트의 클립 보드에 복사하는 방법은 무엇입니까? (0) | 2020.05.13 |