3

I am newbie and trying to develop android app. I used following tutorial and everything is good (i.e. no error/red icon). http://developer.android.com/training/implementing-navigation/nav-drawer.html

However, on activity xml file I am getting following error: The following classes could not be instantiated: - android.support.v4.widget.DrawerLayout (Open Class, Show Exception)

I have searched google and stack overflow. Found similar issue, However no one answered for those. Assuming if someone faced same problem and managed to resolve.

Note: I am using Android-Studio.

Activty.xml have following flow:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout" ...........
tools:context=".MyActivity">

    <FrameLayout
        android:id="@+id/content_frame"........
        android:layout_alignParentEnd="true">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </FrameLayout>

    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"........
        android:background="#111"/>

    </android.support.v4.widget.DrawerLayout>
Ashv
  • 51
  • 1
  • 1
  • 4

5 Answers5

3

The problem is that you're probably using a lower minSdkVersion. I had the same problem, I had set the minSdkVersion to 14, change it to 17 (in the build.gradle) and it renders correctly.

0

I was have the same problem ! just try to change the preview from "L" version of android to 4.4.2 (small android icon) and that will fix the problem :)

Mino
  • 19
  • 4
0

From http://developer.android.com/training/implementing-navigation/nav-drawer.html:

This lesson describes how to implement a navigation drawer using the DrawerLayout APIs available in the Support Library.

Are you sure you link Support Library correctly?

  • Yes, Earlier I was getting error 'class not found'. I searched and found I was not adding support library correctly in build path. Once I did, I start getting error 'Class can not be initiated'. My app is working fine on mobile as expected. Problem is just rendering in studio. – Ashv Sep 17 '14 at 01:38
  • So, how did you fix this? I'm having this same problem right now. Edit: I updated support library, restarted android studio and changed target SDK version to 20 (from 21). This has fixed the problem. I don't know why or how though. – Shashwat Black Nov 08 '14 at 04:24
0

Try this: In the Preview tab, AndroidStudio gives you some options, just click on Clear Cache, and the xml file should render perfectly.

Hasan Hashem
  • 463
  • 5
  • 10
0

I solved this problem installing extra platforms components, following these steps:

Click in the menu "Tools -> Android -> SDK Manager".

Then click in "Appearance & Behavior -> System Settings -> Android SDK".

In "SDK Platforms" tab, check all options above (and including) "Android 4.0.3 (IceCreamSandwich)" option.

Click on "Apply", wait for finish and ready!

Hope it helps.

Silvio Delgado
  • 6,798
  • 3
  • 18
  • 22