получить исключение Inflate с помощью gridlayout

#android #android-layout

#Android #android-layout

Вопрос:

Привет, ребята, я получил android.view.Исключение InflateException: строка двоичного XML-файла # 1: Ошибка при раздувании linearlayout класса, вызванная: java.lang.Исключение ClassNotFoundException: android.view.linearlayout в загрузчике dalvik.system.PathClassLoader[/data/app/com.project.news-2.apk] в указанной строке ниже.

Посмотрите и

HomeActivity

 public void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

}
  

другой метод внутри HomeActivity

 LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

View layout = inflater.inflate(R.layout.dashboard_home ,(ViewGroup) findViewById(R.id.layout_root));


GridView grid = (GridView) layout.findViewById(R.id.gridview);


adapter = new HomeAdapter(this);

adapter.setItems(config); grid.setAdapter(adapter);
  

Домашняя адаптация

 public View getView(int position, View convertView, ViewGroup parent) {



ViewHolder holder

if (convertView == null) { // if it's not recycled,



 convertView = mInflater.inflate(R.layout.dashboard_home, null);  //exception

convertView.setLayoutParams(new GridView.LayoutParams(90, 90));


holder = new ViewHolder();

holder.title = (TextView) convertView.findViewById(R.id.titleIcon);

holder.icon = (ImageView) convertView.findViewById(R.id.imageIcon);

convertView.setTag(holder);


} else {

 holder = (ViewHolder) convertView.getTag();

       }
  

main.xml

     <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@ id/layout_root" android:orientation="vertical"

    android:layout_width="fill_parent" android:layout_height="fill_parent">

    <LinearLayout style="@style/TitleBar">

    <ImageView style="@style/TitleBarLogo"

    android:contentDescription="Text testing" />



<ImageView style="@style/TitleBarSeparator" />

<TextView style="@style/TitleBarText" />



<ImageButton style="@style/TitleBarAction"

android:contentDescription="@string/description_about" android:src="@drawable/info"

android:onClick="onClickAbout" />

</LinearLayout>



<GridView

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:id="@ id/gridview"

    android:numColumns="2"

    />



</LinearLayout>
  

dashboard_home.xml

 <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent" android:padding="10dp">

<ImageView android:id="@ id/imageIcon" android:layout_width="50dip"

android:layout_height="50dip" android:layout_alignParentRight="true"

android:layout_marginRight="3dp" />

<TextView android:id="@ id/titleIcon" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_centerHorizontal="true"

android:layout_alignParentLeft="true" android:layout_marginLeft="3dp"

android:textColor="#FFF" />

</LinearLayout>
  

Ответ №1:

Удалите эти две строки и запустите свой код в HomeActivity.

 LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);     
View layout = inflater.inflate(R.layout.dashboard_home ,(ViewGroup) findViewById(R.id.layout_root));  
  

исключение происходит почему, потому что вы раздуваете dashboard_home.xml во что-то само..

Комментарии:

1. Спасибо DroidBase, ты действительно спас мою работу сегодня!