0

I have been working on a subclass of TextureView based on the answer to this question. Here's my codes:

package com.example.edward.openglproject;

public class GLTextureView extends TextureView implements TextureView.SurfaceTextureListener {

    public GLTextureView(Context context) {
        super(context);
        // Do stuff
    }

    public GLTextureView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // Do stuff
    }

    public GLTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        // Do stuff
    }

    public GLTextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        // Do stuff
    }

// Do other stuff

}

My activity_camera.xml file:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context="com.example.edward.openglproject.CameraActivity">

    <com.example.edward.openglproject.Rendering.GLTextureView
        android:id="@+id/textureView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <!-- Unrelated stuff -->
</FrameLayout>

Whenever I run the program, it crashes where the activity calls

setContentView(R.layout.activity_camera);

and returns this error:

12-07 16:49:01.249 5595-5595/com.example.edward.openglproject E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.edward.openglproject, PID: 5595
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.edward.openglproject/com.example.edward.openglproject.CameraActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.example.edward.openglproject                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                 at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                 at android.os.Looper.loop(Looper.java:164)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                              Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.example.edward.openglproject.Rendering.GLTextureView
                                                                              Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.example.edward.openglproject.TextureView
                                                                              Caused by: java.lang.reflect.InvocationTargetException
                                                                                 at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                                 at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
                                                                                 at android.view.LayoutInflater.createView(LayoutInflater.java:647)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                 at com.example.edward.openglproject.CameraActivity.onCreate(CameraActivity.java:296)
                                                                                 at android.app.Activity.performCreate(Activity.java:6975)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                 at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                 at android.os.Looper.loop(Looper.java:164)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

I have looked around on this site, and most of the solutions involves making the constructors public, which I have done.

Can anyone tell me what's needed to be done?

  • 1
    Just double-checking, but do you have `` on the first line of your `activity_camera.xml` layout file? – Michael Dodd Dec 07 '17 at 15:31
  • 1
    This line also looks a little odd: `Error inflating class com.example.edward.openglprojectTextureView` - Like it's missing the `.` between the final package and the class name – Michael Dodd Dec 07 '17 at 15:34
  • @MichaelDodd Yes I have that line on my `activity_camera.xml` file, and the missing `.` was because my copy/paste/edit went wrong somehow. – Edward Nguyen Dec 07 '17 at 16:00
  • Any chance your class is in fact `abstract`? `newInstance0()` throws when trying to instantiate an abstract class or an interface, or if you don't have access to the constructor (e.g. misssing `public`). – laalto Dec 07 '17 at 16:07
  • Also the code snippet you posted has the class in another package than is referenced in XML. – laalto Dec 07 '17 at 16:09
  • @laalto can a class be abstract without being declared so? And I've fixed that, but the same error keeps popping up – Edward Nguyen Dec 07 '17 at 16:33
  • 1
    Nope, just wondering since apprently the code you posted is not your actual code and that left me with open questions. – laalto Dec 07 '17 at 16:34
  • Please update your code if you have `import` lines. Your `TextureView` seems an original class without imports (and log shows that), and it should be android.view.TextureView as normal. – Toris Dec 07 '17 at 17:22

1 Answers1

0

Should correct package name of GLTextureView in code or xml.

In code: com.example.edward.openglproject.GLTextureView
In xml: com.example.edward.openglproject.rendering.GLTextureView
In log: com.example.edward.openglproject.Rendering.GLTextureView

I also think it's odd to have original TextureView (not of Android one).
In log: com.example.edward.openglproject.TextureView

Toris
  • 2,348
  • 13
  • 16