https://kotlinlang.org logo
#splitties
Title
# splitties
n

nickk

07/30/2019, 3:04 PM
Here is a stacktrace
Copy code
java.lang.ClassNotFoundException: com.louiscad.splittiessample.main.MainUi
	at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:201)
	at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61)
	at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:135)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:235)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at splitties.views.dsl.idepreview.UiPreView.<init>(UiPreView.kt:60)
	at splitties.views.dsl.idepreview.UiPreView.<init>(UiPreView.kt:43)
	at splitties.views.dsl.idepreview.UiPreView.<init>(UiPreView.kt)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:403)
	at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:186)
	at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:144)
	at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:309)
	at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:418)
	at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:429)
	at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:333)
	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
	at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:323)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:394)
	at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:200)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:572)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:698)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
If I clean the project, I get a slightly different error:
Copy code
Missing classes: The following classes could not be found:
 splitties.views.dsl.idepreview.UiPreView
l

louiscad

07/30/2019, 11:01 PM
@nickk Do the preview xml files in the sample work for you? Also, you can always try reopening the project, or restarting the IDE
n

nickk

07/31/2019, 8:19 AM
@louiscad This is the sample. (Restarting the IDE does not help)
Splitties opened with AS 3.5 RC1
l

louiscad

07/31/2019, 9:53 AM
@nickk Are you on the develop branch or the master branch?
n

nickk

07/31/2019, 9:54 AM
On master
l

louiscad

07/31/2019, 10:20 AM
Can you try on develop, and build the sample Android app before checking again?
n

nickk

07/31/2019, 10:20 AM
Sure
@louiscad Same issues. BTW, this stacktrace with negative line numbers is very sexy…
Copy code
Exception Details java.lang.ClassNotFoundException: com.louiscad.splittiessample.main.MainUi   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)   at java.lang.Class.forName0(Class.java:-2)   at java.lang.Class.forName(Class.java:264)   at splitties.views.dsl.idepreview.UiPreView.<init>   ... (UiPreView.kt:60)   at splitties.views.dsl.idepreview.UiPreView.<init>(UiPreView.kt:43)   at splitties.views.dsl.idepreview.UiPreView.<init>(UiPreView.kt:-1)   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)   at android.view.LayoutInflater.inflate(LayoutInflater.java:492)   at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
Also, if I click the “build project” link in the preview pane, then the build fails… (If this is an unexpected error you can also try to build the project, then manually refresh the layout.) I get 31 AAPT errors, like this one:
Copy code
/Users/nk/Projects/android/Splitties/modules/views-dsl-material/build/intermediates/packaged_res/debug/values/values.xml:27:5-59:13: AAPT: error: resource style/Widget.MaterialComponents.BottomAppBar (aka splitties.views.dsl.material.test:style/Widget.MaterialComponents.BottomAppBar) not found.
l

louiscad

07/31/2019, 2:03 PM
@nickk Thanks for the heads up. I just reached my computer and I'm seeing the problem: there's a mismatch between the
applicationId
and a package move I did some time ago. The new package where the code is located is
com.example.splitties.
but the
applicationId
is still
com.louiscad.splittiessample
. Since
UIPreview
uses
context.packageName
,
applicationId
is returned, and the class doesn't exist. Workaround is to use
splitties_class_fully_qualified_name
in xml instead of
splitties_class_package_name_relative
. I opened an issue to improve it: https://github.com/LouisCAD/Splitties/issues/202
n

nickk

07/31/2019, 2:05 PM
I’m glad I helped. Not sure if this feature is super important. With anko it was broken all the time, and I abandoned trying to use it 😉
But my question remains: negative line number in the stack trace? WTF… 🤔
l

louiscad

07/31/2019, 2:12 PM
It's probably Kotlin conversion. I found out of range line numbers in stacktraces quite often when using inline symbols or coroutines. I admit I don't use
UIPreview
a lot, but I can tell you it works, and it's better if the sample isn't broken in subtle ways. Since Android Studio 3.4, there's the resource manager which makes
UIPreview
quite useful when coming to a new project as you can glance the existing layouts.
n

nickk

07/31/2019, 2:15 PM
And, yes, it does work 😄
IDE Preview
l

louiscad

07/31/2019, 5:20 PM
I just pushed an improvement for this on the develop branch. You can update it and use the "Resource Manager" tool window, then selecting the "android-app" module, and the "layout" tab to see all the previews. I also improved the display of error messages. You'll now see a red warning panel above blue text on white background to show the reason of the preview failure (class not found, wrong type, etc…).
17 Views