2

I am using Shamanland FontIconView but my Activity can't be started and my app crashes

Steack Trace:

     FATAL EXCEPTION: main
   Process: com.example.mmido.asfarandroid, PID: 14010
   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mmido.asfarandroid/com.example.mmido.asfarandroid.As
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2385)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2436)
       at android.app.ActivityThread.access$800(ActivityThread.java:157)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
       at android.os.Handler.dispatchMessage(Handler.java:110)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:5398)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
       at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.shamanland.fonticon.FontIconView
       at android.view.LayoutInflater.createView(LayoutInflater.java:620)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
       at com.example.mmido.asfarandroid.AsfarApp.PaymentActivity.onCreate(PaymentActivity.java:13)
       at android.app.Activity.performCreate(Activity.java:5264)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2349)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2436) 
       at android.app.ActivityThread.access$800(ActivityThread.java:157) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374) 
       at android.os.Handler.dispatchMessage(Handler.java:110) 
       at android.os.Looper.loop(Looper.java:193) 
       at android.app.ActivityThread.main(ActivityThread.java:5398) 
       at java.lang.reflect.Method.invokeNative(Native Method) 
       at java.lang.reflect.Method.invoke(Method.java:515) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
       at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.constructNative(Native Method)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       at android.view.LayoutInflater.createView(LayoutInflater.java:594)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
       at com.example.mmido.asfarandroid.AsfarApp.PaymentActivity.onCreate(PaymentActivity.java:13) 
       at android.app.Activity.performCreate(Activity.java:5264) 
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2349) 
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2436) 
       at android.app.ActivityThread.access$800(ActivityThread.java:157) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374) 
       at android.os.Handler.dispatchMessage(Handler.java:110) 
       at android.os.Looper.loop(Looper.java:193) 
       at android.app.ActivityThread.main(ActivityThread.java:5398) 
       at java.lang.reflect.Method.invokeNative(Native Method) 
       at java.lang.reflect.Method.invoke(Method.java:515) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
       at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.IllegalStateException
       at com.shamanland.fonticon.FontIconTypefaceHolder.getTypeface(FontIconTypefaceHolder.java:11)
       at com.shamanland.fonticon.FontIconView.<init>(FontIconView.java:129)
       at java.lang.reflect.Constructor.constructNative(Native Method) 
       at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
       at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
       at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
       at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
       at com.example.mmido.asfarandroid.AsfarApp.PaymentActivity.onCreate(PaymentActivity.java:13) 
       at android.app.Activity.performCreate(Activity.java:5264) 
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2349) 
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2436) 
       at android.app.ActivityThread.access$800(ActivityThread.java:157) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374) 
       at android.os.Handler.dispatchMessage(Handler.java:110) 
       at android.os.Looper.loop(Looper.java:193) 
       at android.app.ActivityThread.main(ActivityThread.java:5398) 
       at java.lang.reflect.Method.invokeNative(Native Method) 
       at java.lang.reflect.Method.invoke(Method.java:515) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:940) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
       at dalvik.system.NativeStart.main(Native Method) 

My Layout:

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/pf_tittle_header_height"
        android:background="@color/pf_gray">

        <com.shamanland.fonticon.FontIconView
            android:id="@+id/backButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_margin="@dimen/pf_border_space"
            android:clickable="true"
            android:onClick="onBackPressed"
            android:text="@string/icon_left_circled"
            android:textColor="@android:color/white"
            android:textSize="@dimen/pf_back_icon_txt_size"
            app:pressedGlowColor="@color/pf_green"
            app:pressedGlowRadius="@dimen/pf_icon_glow_radius" />

Line #15 is this line <com.shamanland.fonticon.FontIconView i checked String values and dimension used in FontIconView and they are correct .what is the error here please?

Thanks.

Asmaa Rashad
  • 593
  • 5
  • 28
  • Is there another "caused by" caluse down the log? The reason I'm asking is this: http://stackoverflow.com/questions/6020719/what-could-cause-java-lang-reflect-invocationtargetexception – Vaiden Aug 01 '16 at 13:12
  • are you use this third party class? – Vishal Thakkar Aug 01 '16 at 13:14
  • @Vaiden i updated the log with "all Caused by" clauses – Asmaa Rashad Aug 01 '16 at 13:19
  • @AndroidDeveloper yes i do i added it in dependencies in gradle file – Asmaa Rashad Aug 01 '16 at 13:19
  • The last time I had an inflater issue like this was when I forgot to put a line in build.gradle dependency. Can you inspect the apk and check if you have FontIconView there? – Fabio Aug 01 '16 at 13:22
  • @Fabio when i stop on `fonticon.FontIconView` and click go to declaration it takes me to `FontIconView` class already – Asmaa Rashad Aug 01 '16 at 13:24
  • @Asmaa the illegal state exception is most likely to be the cause. If you still want to check for the class inside the apk, rename the apk to .zip, open with WinZip or similar and see if you can find the corresponding .class file there. – Fabio Aug 01 '16 at 13:42
  • @Fabio i renamed the App apk and it can't be opened as ziped file – Asmaa Rashad Aug 01 '16 at 13:55

2 Answers2

3

I was also facing the same problem day before yesterday in my project, so the solution I found is: Just paste your .ttf file inside the asset folder in your project (if folder is not there just create one inside app->src->main) and initialize the FontIconTypefaceHolder() in your main activity inside onCreate() method. Like as

FontIconTypefaceHolder.init(getAssets(),"icon.ttf");
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
1

The constructor throws an IllegalStateException due to:

Caused by: java.lang.IllegalStateException
       at com.shamanland.fonticon.FontIconTypefaceHolder.getTypeface(FontIconTypefaceHolder.java:11)

Since this project is open source, put a breakpoint there and debug the issue.

Vaiden
  • 15,728
  • 7
  • 61
  • 91
  • i will try that now – Asmaa Rashad Aug 01 '16 at 13:25
  • i added this library in dependencies in gradle file i don't know where should i put a breakpoint? – Asmaa Rashad Aug 01 '16 at 13:30
  • Write FontIconTypefaceHolder icon; anywhere, alt+ left click the class name will take you to the source code. Then create a breakpoint there. – Fabio Aug 01 '16 at 13:46
  • i did that now and this is the line that cause the exception `setTypeface(FontIconTypefaceHolder.getTypeface());` – Asmaa Rashad Aug 01 '16 at 13:58
  • `public static Typeface getTypeface() { if (sTypeface == null) { throw new IllegalStateException(); } return sTypeface; }` sTypeface is null so it throws exception .. why is that ?? – Asmaa Rashad Aug 01 '16 at 14:12
  • @AsmaaRashad a wild guess here - this is an attribute that the library expects in the XML. Look at where sTypeface is assigned for the exact attribute name. – Vaiden Aug 01 '16 at 14:25
  • @AsmaaRashad Did you solve this problem? I am facing the same. – UdiT Sep 21 '16 at 08:40