Navigation Box - The box layout cannot be created.

I am trying to implement a navigation box in my application, but I am having serious problems with it. Right now, my problem is that I want to put my MainContent inside the Layer Layout as follows:

<android.support.v4.widget.DrawerLayout android:id = "@+id/drawer_layout" xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "match_parent" android:layout_height = "match_parent" > <FrameLayout [...] </FrameLayout> </android.support.v4.widget.DrawerLayout> 

But I get this error code

The following classes cannot be created: - android.support.v4.widget.DrawerLayout (Open Class, Show Exception)

This is the exception information:

 java.lang.ClassNotFoundException: android.support.v4.widget.DrawerLayoutImpl at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:148) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.lang.ClassLoader.defineClass(ClassLoader.java:642) at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:195) at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:191) at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:152) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at com.android.tools.idea.rendering.RenderClassLoader.loadClassFromJar(RenderClassLoader.java:78) at org.jetbrains.android.uipreview.ProjectClassLoader.loadClassFromModuleOrDependency(ProjectClassLoader.java:108) at org.jetbrains.android.uipreview.ProjectClassLoader.load(ProjectClassLoader.java:89) at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:56) at org.jetbrains.android.uipreview.ProjectClassLoader.findClass(ProjectClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:173) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:96) at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:385) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:401) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332) at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:575) at com.android.tools.idea.rendering.RenderService$3.compute(RenderService.java:564) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932) at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:564) at com.android.tools.idea.rendering.RenderService.render(RenderService.java:691) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:604) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:80) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:546) at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178) at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212) at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171) at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:541) 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:327) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 

I follow this guide http://developer.android.com/training/implementing-navigation/nav-drawer.html But so far it does not work at all. Maybe someone has a better tutorial on how to properly implement the navigation box with Android 5.0?

Thanks in advance for your help.

Regards, John

+6
source share
4 answers

Once here with the same problem, first of all, pay attention to what Christer Noordwick commented:

Think it's a bug in the latest version of the tools: https://code.google.com/p/android/issues/detail?id=78090

We have the same thing in the designer, but this is normal when working. It worked without problems until the release of API level 21 SDK.

As I can see, you have 4 options:


Option 1: Go back to Android before 5.0 Use and compile your code using SDK 20

Change build.gradle to the following:

 apply plugin: 'com.android.application' android { compileSdkVersion 20 buildToolsVersion "20.0.0" defaultConfig { applicationId "com.example.yourapp" minSdkVersion 8 targetSdkVersion 20 versionCode 1 versionName "1.0" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-v4:20.0.0' } 

change the following lines to what ever matched your project:

  applicationId "com.example.yourapp" minSdkVersion 8 

Most likely, you will also have to change the "res \ v21 \ styles.xml":

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="android:Theme.Material.Light"> </style> </resources> 

in

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="android:Theme.Holo.Light"> </style> </resources> 

How material topics are presented on Lollipop / Android 5.0

Synchronize your project with a new gradle file, wait for the synchronization to complete, and you will be fine, you should see a preview of the layout

Sync your project with gradle files


Option 2: update your code in the text

The code will compile and work just fine, just update your code in the text, without previewing. Instead, make changes and try them on the emulator or on the Android device itself.


Option 3: combine the first 2 options

Use option 1, do what you need to do for layouts (if it doesn't need anything specific from SDK 21), and when done, revert the changes made to build.gradle and styles.xml so you can enjoy the new Lollipop eye candy, just test it on an emulator or device, as suggested on option 2


Option 4: wait to fix the error

just this.


Optional long shot option:

If you installed a stable build of Android Studio, try Beta or Canary, who knows, maybe there is a fix implemented to solve this problem on one of them (I have a stable build, so I don’t know). Or try Eclipse

+5
source

You mentioned a bug from the user interface editor. This happens when a user view cannot be viewed in the editor. It's not a problem. If you run the application, everything should be fine.

0
source

This is an example of the code “Navigation Box - Box Layout Code”, you can use it without errors.

  <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/left_drawer" android:layout_width="330dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="multipleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="@drawable/gradient_gray"> [...] </FrameLayout> </android.support.v4.widget.DrawerLayout> 
0
source

Think it's a bug in the latest version of the tools: https://code.google.com/p/android/issues/detail?id=78090

We have the same thing in the designer, but this is normal when working. It worked without problems before the release of the SDK at API level 21.

0
source

Source: https://habr.com/ru/post/977138/


All Articles