vinaygaba / CreditCardView

💳 CreditCardView is an Android library that allows developers to create the UI which replicates an actual Credit Card.
797 stars 143 forks source link

Preview in Android Studio has rendering problems #8

Closed biddster closed 9 years ago

biddster commented 9 years ago

I've added the credit card to one of my fragments. When I select the design view for that fragment I get the following exception:

java.lang.RuntimeException: Font asset not found fonts/creditcard2.ttf
    at android.graphics.Typeface.createFromAsset(Typeface.java:190)
    at com.vinaygaba.creditcardview.CreditCardView.init(CreditCardView.java:73)
    at com.vinaygaba.creditcardview.CreditCardView.<init>(CreditCardView.java:59)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:437)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:154)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:93)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:190)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:410)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:511)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:499)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:499)
    at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:611)
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:608)
    at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:364)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:608)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:630)
    at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
vinaygaba commented 9 years ago

I had recently changed the font as the font previous used did not permit being redistributed. Could you delete the library from the cache and build the project again. That should fix this I think.

vinaygaba commented 9 years ago

You can find the library in this location on your machine .gradle\caches\modules-2\files-2.1\com.vinaygaba\creditcardview\ . Just delete the 1.0.2 folder there and add the dependency again and that should do it

biddster commented 9 years ago

Still getting the same exception I'm afraid. Has something not fully propagated across maven?

vinaygaba commented 9 years ago

I've found a similar issue in another popular library - https://github.com/rengwuxian/MaterialEditText/pull/48 Will work on fixing this based on the suggestions made in the link.

vinaygaba commented 9 years ago

Hi, I have fixed this error and I will be releasing it in v1.0.3 of the library which should be out in the next couple of days :) Closing the issue. Thanks for your contribution.

biddster commented 9 years ago

No problem, thanks for the assistance.

biddster commented 9 years ago

Confirming fixed in 1.0.3.