1

First of all, I researched alot and this question is not a duplicate of Rendering Issue in Android Studio its answer doesn't fix my problem (i already have the same configuration that is in its answer). Secondly I tried cleaning project, rebuilding project, running gradle sync too. Issue still persist.

After starting a new project, i used to load a template basic activity but the layout xml files are actually not rendering.

Error: It says Failed to instantiate one or more classes inside that i see

The following classes could not be instantiated:
    - android.support.design.widget.CoordinatorLayout (Open Class, Show Exception, Clear Cache)
    - android.support.design.widget.AppBarLayout (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.
If this is an unexpected error you can also try to build the project, then manually refresh the layout.
Exception Details
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
Copy stack to clipboard

my styles.xml file is:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
        <item name="floatingActionButtonStyle">@style/Widget.Design.FloatingActionButton</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>

My gradle is using this dependency: and compilation and target sdk version is 28

implementation 'com.android.support:appcompat-v7:28.0.0'

Right now it looks like:

enter image description here

EDIT 1: So now at this point, i tried many things and found myself that the rendering issue is only in SdkVersion 28. When I use

android {
    compileSdkVersion 27
    defaultConfig {
        targetSdkVersion 27
        ...
    }
    ...
}

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    ...
}

It doesn't appear to be, so I want to investigate what's wrong with sdk version 28? I mean like whenever you make a project you get default config for version 28 and when i try this above snippet i still get warning that v27 is older, why? if v28 not stable enough then why is it default? I don't understand I want some useful answer for why this is!

Thanks everyone who used time to read my question.

1 Answers1

0

Before proceeding with the answer, make sure you have the latest Android Studio. It handles API v28 in a much better way. This update on its own might solve your problem, but if it doesn't, read below:

AndroidX

Try migrating to AndroidX. In the latest Android Studio 3.2 there is a feature called 'Refactor to AndroidX' under the 'Refactor' menu, which makes the whole process easier.

AndroidX is basically google renaming all of the packages to make the naming clearer. More information on that can be found here and here.


I know this is not a direct answer to your question, but I am confident it will solve it. There are many bugs and other irritating errors that Android Studio produces, that I don't see any other IDE makes - I am referring to those that are unclear about what went wrong.

I believe by making AndroidX google addresses this issue in some way. It does definitely make some things clearer and easier, and I recommend migrating to it, in order to solve your problem, and for good practice.

Ido Fang Bentov
  • 178
  • 1
  • 2
  • 9