android - Error inflating my Custom TextView from Library -
i have customtextview loads custom library. can't inflate in main_layout , app stops working. find if put mytextview in main project works fine , problem load mylib.
public class mytextview extends textview { public mytextview(context context){ super(context); } public mytextview(context context, attributeset attrs) { super(context, attrs); initattr(attrs); } public mytextview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); initattr(attrs); } private void initattr(attributeset attrs) { typedarray a=getcontext().obtainstyledattributes( attrs, r.styleable.myview); super.settext("blablabla"); a.recycle(); }
i warning in xml designing: the following classes not found on custom class , although class loads auto completely! think thing wrong library. create library in android studio project strucure / new module / android library
this how call it:
<com.kenji.mylib.mytextview android:layout_width="50dp" android:layout_height="50dp"/>
and error:
04-29 14:22:35.645 19805-19805/com.kenji.myapplication e/androidruntime? fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.kenji.myapplication/com.kenji.myapplication.mainactivity}: android.view.inflateexception: binary xml file line #13: error inflating class com.kenji.mylib.mytextview.mytextview @ android.app.activitythread.performlaunchactivity(activitythread.java:1659) @ android.app.activitythread.handlelaunchactivity(activitythread.java:1675) @ android.app.activitythread.access$1500(activitythread.java:121) @ android.app.activitythread$h.handlemessage(activitythread.java:943) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:130) @ android.app.activitythread.main(activitythread.java:3701) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:866) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:624) @ dalvik.system.nativestart.main(native method) caused by: android.view.inflateexception: binary xml file line #13: error inflating class com.kenji.mylib.mytextview.mytextview @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:581) @ android.view.layoutinflater.rinflate(layoutinflater.java:623) @ android.view.layoutinflater.inflate(layoutinflater.java:408) @ android.view.layoutinflater.inflate(layoutinflater.java:320) @ android.view.layoutinflater.inflate(layoutinflater.java:276) @ android.support.v7.app.actionbaractivitydelegatebase.setcontentview(actionbaractivitydelegatebase.java:240)
public class mytextview extends textview { public mytextview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); init(); } public mytextview(context context, attributeset attrs) { super(context, attrs); init(); } public mytextview(context context) { super(context); init(); } private void init() { settext("blablabla"); } }
and in layout
<yourpackage.mytextview android:layout_width="wrap_content" android:layout_height="wrap_content" />
Comments
Post a Comment