Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom view CustomView is not using the 2- or 3-argument View constructors

I know I could do as the warning directs me to; create 2- or 3-argument View constructor.

However, the CustomView is from a 3rd party SDK which is final, so I feel like I must use this one to take full advantage of the SDK. Anyhow, there's no chance to extend final CustomView.

Is there any workaround?

On a side note, the view I'm trying to use is MetaioSurfaceView by Metaio.


Below is the logcat message right after the crash:

A/WTF(18270): Unable to start activity ComponentInfo{com.suzi.application/com.suzi.application.CustomActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class com.metaio.sdk.MetaioSurfaceView
A/WTF(18270): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.suzi.application/com.suzi.application.CustomActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class com.metaio.sdk.MetaioSurfaceView
A/WTF(18270):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
A/WTF(18270):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
A/WTF(18270):   at android.app.ActivityThread.access$700(ActivityThread.java:165)
A/WTF(18270):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
A/WTF(18270):   at android.os.Handler.dispatchMessage(Handler.java:99)
A/WTF(18270):   at android.os.Looper.loop(Looper.java:176)
A/WTF(18270):   at android.app.ActivityThread.main(ActivityThread.java:5455)
A/WTF(18270):   at java.lang.reflect.Method.invokeNative(Native Method)
A/WTF(18270):   at java.lang.reflect.Method.invoke(Method.java:525)
A/WTF(18270):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
A/WTF(18270):   at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
A/WTF(18270):   at dalvik.system.NativeStart.main(Native Method)
like image 358
Attacktive Avatar asked Feb 11 '23 16:02

Attacktive


1 Answers

if you have a custom view and customView has only one type of constructor like default constructor

when you add the custom view in xml than xml wants CustomView(Context context, AttributeSet attrs), CustomView(Context context, AttributeSet attrs, int defStyle) these type of constructor.

and if your custom view is belongs to 3rd party lib then you can only add by Java code by default constructor like new CustomView();

like image 54
Amit Kumar Avatar answered Feb 16 '23 04:02

Amit Kumar