2017-12-07 4 views
0

私はthis questionの答えに基づいてTextureViewのサブクラスを作成しています。ここに私のコードです:バイナリXMLファイルライン#0:エラーが発生しました。クラスTextureView

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 

} 

マイactivity_camera.xmlファイル:私は、プログラムを実行するたびに

<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> 

活動が

setContentView(R.layout.activity_camera); 

を呼び出すところ、それがクラッシュすると、このエラーが返されます。

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) 

私はこのサイトを見回しました。ほとんどのソリューションでは、私が行ったコンストラクタをパブリックにする必要があります。

何が必要なのか教えてもらえますか?

+0

「activity_camera.xml」レイアウトファイルの最初の行に '<?xml version =" 1.0 "encoding =" utf-8 "?> ? –

+1

この行もちょっと変わっています: 'Error inflating class com.example.edward.openglprojectTextureView' - 最終パッケージとクラス名の間に' .'がありません。 –

+0

@MichaelDoddはい私は 'activity_cameraにその行があります。 xml'ファイルであり、コピー&ペースト/編集が何らかの形で間違っていたために '.'がありませんでした。 –

答えて

0

コードまたはXMLでGLTextureViewのパッケージ名を修正する必要があります。コードで

:XMLでcom.example.edward.openglproject.GLTextureView
:ログでcom.example.edward.openglproject.rendering.GLTextureView
com.example.edward.openglproject.Rendering.GLTextureView

また、私はそれが(ないAndroid oneの)元TextureViewを持っている奇妙だと思います。
ログイン:com.example.edward.openglproject.TextureView

+0

修正済みですが、それでも同じエラーがあります。 –

関連する問題