Android CustomView zu Fragment hinzufügen

  • Antworten:2
Daniel
  • Forum-Beiträge: 1

28.02.2017, 13:26:59 via Website

Hey, ich bin gerade dabei eine Zeichenapp zu entwickeln und verharre schon etwas länger an einem Problem. Ich möchte die CustomView, die ich zum zeichnen erstellt habe, in einem Fragment hinzufügen. Allerdings bekomme ich immer eine InflateException und die App startet nicht.

.

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: de.sentoon.touchtesterv4, PID: 11743
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{de.sentoon.touchtesterv4/de.sentoon.touchtesterv4.MainActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class de.sentoon.touchtesterv4.DrawingView
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2788)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1503)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6209)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                   Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class de.sentoon.touchtesterv4.DrawingView
                   Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class de.sentoon.touchtesterv4.DrawingView
                   Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
                      at java.lang.Class.getConstructor0(Class.java:2204)
                      at java.lang.Class.getConstructor(Class.java:1683)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:618)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                      at de.sentoon.touchtesterv4.MainActivity.onCreate(MainActivity.java:27)
                      at android.app.Activity.performCreate(Activity.java:6745)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2788)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1503)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6209)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

— geändert am 28.02.2017, 13:27:24

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

28.02.2017, 13:54:44 via Website

Hallo Daniel,
Herzlich wilkommen hier im Forum :)


Schau dir mal die Exception genauer an:
Binary XML file line #20: Binary XML file line #20: Error inflating class de.sentoon.touchtesterv4.DrawingView
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class de.sentoon.touchtesterv4.DrawingView

Scheint so als wäre was mit einem XML File in Zeile 20 nicht in Ordnung...

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
pepperonas
  • Forum-Beiträge: 434

01.03.2017, 02:26:23 via Website

Sieht fast so aus :P Könnte aber auch sein, dass sich der Konstruktor vorzeitig in die Osterferien verabschiedet hat :D

Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
                      at java.lang.Class.getConstructor0(Class.java:2204)

... mit Code wäre es jedenfalls einfacher :)

Open Source

Antworten