Skip to content Skip to sidebar Skip to footer

Mockview Cannot Be Cast To Android.view.viewgroup In Xml

While checking in the graphical layout I am getting this error: Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGro

Solution 1:

This Error was occurred because of wrong implementation of the drawer layout. I place a three direct layout to Drawer layout the error would be occurring. As per the Google document, It took the two layout directly.

In Drawer Layout, If I place a two direct Layout solved the problem. That's why I am using the Frame Layout as a parent layout below Drawer Layout then finally add a List View to show the navigation drawer.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/drawer_layout"android:layout_width="match_parent"android:layout_height="match_parent" ><FrameLayoutandroid:id="@+id/frame_container"android:layout_width="match_parent"android:layout_height="match_parent" ><RelativeLayoutandroid:id="@+id/container"android:layout_width="wrap_content"android:layout_height="match_parent" ><TextViewandroid:id="@+id/textviewHeading"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:layout_marginTop="5dp"android:fontFamily="fonts/Dosis.otf"android:text="@string/heading_chapter"android:textSize="25sp"android:visibility="gone" /><ListViewandroid:id="@+id/listviewChapters"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_above="@+id/imageviewBanner"android:layout_below="@+id/textviewHeading"android:layout_marginTop="5dp" ></ListView><ImageViewandroid:id="@+id/imageviewBanner"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:src="@drawable/banner"android:visibility="invisible" /></RelativeLayout></FrameLayout><ListViewandroid:id="@+id/list_slidermenu"android:layout_width="240dp"android:layout_height="match_parent"android:layout_gravity="start"android:background="@color/list_background"android:choiceMode="singleChoice"android:divider="@color/list_divider"android:dividerHeight="1dp"android:listSelector="@drawable/list_selector" /></android.support.v4.widget.DrawerLayout>

Solution 2:

I have found this problem into my project then i added the support.v4.jar file into my project then it solve my problem so i think you can try this.

Solution 3:

use this

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

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.sun_soft.app_maker_new.MainActivity"
        tools:ignore="MergeRootFrame" />

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#ffffff"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

    <ListView
        android:id="@+id/right_drawer"
        android:layout_width="@dimen/paanelsize"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#ffffff"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

then later on you have to refer the listview in mainactivity and have to make a adapter and inflate view for listitem.

i think in your code you are wrong casting some view. please post code.

Solution 4:

I would advice you to check the resources referenced in your layout.

In my case, I made a mistake by saving a psd file as a png file. When this 'bad' png file is referenced in my layout, Eclipse ends up with such error, i.e.

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.widget.ImageView

Just because the png file referenced in ImageView was, in fact, a psd file, i.e.:

android:src="@drawable/my_psd_file_with_wrong_png_extension"

Hope this helps.

Post a Comment for "Mockview Cannot Be Cast To Android.view.viewgroup In Xml"