Reputation: 2573
I'm working on this android project on eclipse. I created two gridLayouts and a text field on main activity. It keeps on showing this warning in a window "The following classes could not be instantiated: - android.support.v7.widget.GridLayout (Open Class, Show Error Log)" but as i try to add a button to the GridLayout, the activity freezes and now it shows following message "NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.
Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup Exception details are logged in Window > Show View > Error Log The following classes could not be instantiated: - android.support.v7.widget.GridLayout (Open Class, Show Error Log)" My xml file is:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/res/com.example.simple_calculator">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="94dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<android.support.v7.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="232dp"
android:layout_marginTop="100dp" >
</android.support.v7.widget.GridLayout>
<android.support.v7.widget.GridLayout
android:layout_width="232dp"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
app:columnCount="1" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_column="0"
app:layout_gravity="left|top"
app:layout_row="0"
android:text="Button" />
</android.support.v7.widget.GridLayout>
</FrameLayout>
I already tried importing android-sdk-[platform]/extras/android/support/v7/gridlayout, but still same error.
Upvotes: 3
Views: 10414
Reputation: 71
Try using following code(I have modified your code, not added any other stuff) :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/res/com.example.simple_calculator">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="94dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<GridLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="232dp"
android:layout_marginTop="100dp" >
</GridLayout>
<GridLayout
android:layout_width="232dp"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:text="Button" />
</GridLayout>
</FrameLayout>
In this code Grid Layout and the app:column and gravity parts are modified and the exception reported was corrected and code works fine and also for the layout rules please check the following link:
http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/
Hope this helps in resolving problem :)
Best Regards
Upvotes: 1