问题
This is the error I'm getting in my layout XML files:
Exception raised during rendering: 0
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- View (Change to android.view.View, Fix Build Path, Edit XML)
My Xml File is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_view_main_lin_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FFFFFF"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/search_view_flipper"
android:layout_width="fill_parent"
android:visibility="gone"
android:layout_height="@dimen/list_view_row_size" >
<LinearLayout
android:id="@+id/search_lin_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TextView
android:id="@+id/search_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:drawableLeft="@drawable/search_ico"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:text="@string/search_text_view"
android:textColor="#FF37200e"
android:textSize="@dimen/text_view_left_menu" />
</LinearLayout>
<RelativeLayout
android:id="@+id/search_edit_text_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/search_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/rounded_edittext"
android:drawableLeft="@drawable/searchgray_ico"
android:drawablePadding="05dp"
android:textCursorDrawable="@null"
android:hint="@string/search_text_view"
android:imeOptions="actionDone"
android:paddingLeft="10dp"
android:paddingRight="35dp"
android:singleLine="true"
android:textSize="@dimen/text_view_left_menu"
android:textColor="#000000" />
<ImageButton
android:id="@+id/cancel_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/search_edit_text"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:src="@drawable/cross"
android:background="#00000000"
android:padding="10dp" />
</RelativeLayout>
</ViewFlipper>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/listview_divider" />
<LinearLayout
android:id="@+id/featured_lin_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/list_view_row_size"
android:gravity="center_vertical" >
<TextView
android:id="@+id/featured_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/featured_text_view"
android:textColor="#FF37200e"
android:textSize="@dimen/text_view_left_menu" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:contentDescription="@string/featured_text_view"
android:src="@drawable/featured_ico" />
</LinearLayout>
<View
android:id="@+id/view_featured_divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/listview_divider" />
<LinearLayout
android:id="@+id/favorites_lin_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/list_view_row_size"
android:gravity="center_vertical" >
<TextView
android:id="@+id/favorites_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/favorites_text_view"
android:textColor="#FFb2661A"
android:textSize="@dimen/text_view_left_menu" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:contentDescription="@string/favorites_text_view"
android:src="@drawable/favorites_active_ico" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/listview_divider" />
<ListView
android:id="@+id/main_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:divider="@android:color/transparent"
android:smoothScrollbar="true"
android:cacheColorHint="#00000000"
android:dividerHeight="0dp"
android:fadingEdge="none"
android:scrollbars="none" >
</ListView>
I'm using Eclipse Juno. Currently my project Build target is android 4.1. I've tried by lowering the API level also but it doesn't help me.
Due to this I'm not able to see the graphical layout of my XML files. Please anybody help me.
回答1:
There is a mismatch between your target SDK version and your Graphical Layout target, should be an easy fix.
If you don't know it off the top of your head, you can get your Android SDK version for your project from right-clicking on your project name, going to Properties, selecting "Android", and looking for the test in the "platform" column for the row with a checkmark.
Then in the Graphical Layout for your XML file, in the top right in between the Locale selector and the Create button is a drop-down for Android versions. Change this to match the one for your project, and the errors should go away the graphical preview will render correctly.
回答2:
its very semple
all you have to do is change android version used to render layout in eclipse
android version used to render layout Button
hope that help you.
来源:https://stackoverflow.com/questions/15495941/xml-error-in-eclipse-while-viewing-graphical-layout-of-xml