2017-08-15 71 views
0

我修改的XML代碼,但它仍然是錯誤:我在Android中有一個「充氣異常」錯誤工作室

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/list" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.android.miwok.NumbersActivity"/> 

,這是java代碼..

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.ArrayAdapter; 
import android.widget.GridView; 
import android.widget.LinearLayout; 
import android.widget.ListView; 
import android.widget.TextView; 

import java.util.ArrayList; 

public class NumbersActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_numbers); 


     ArrayList<String> words = new ArrayList<String>(); 

     words.add(0, "one"); 
     words.add(1, "two"); 
     words.add(2, "three"); 
     words.add(3, "four"); 
     words.add(4, "five"); 
     words.add(5, "six"); 
     words.add(6, "seven"); 
     words.add(7, "eight"); 
     words.add(8, "nine"); 
     words.add(9, "ten"); 





     ArrayAdapter<String> itemsAdapter = 
       new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, words); 



     ListView listView = (ListView) findViewById(R.id.list); 





     listView.setAdapter(itemsAdapter); 


    } 
} 

android.view.InflateException: Binary XML file line #2: Error inflating class GridViewView

我已經更改爲ListView,但它仍然存在。

請給一些解決方案,我在Udacity Android課程。

+0

請[編輯]你的問題發佈完整的堆棧跟蹤。 –

+0

嘗試使用ListView清理項目 – user8256287

+0

出於興趣 - 所有這些維都使用了定義和有效的? – Ewald

回答

1

我用相同的代碼重新創建項目,唯一改變的是你的xml文件的填充。
看一看:

的Java:

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

import java.util.ArrayList; 

public class NumbersActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_numbers); 

     ArrayList<String> words = new ArrayList<String>(); 

     words.add(0, "one"); 
     words.add(1, "two"); 
     words.add(2, "three"); 
     words.add(3, "four"); 
     words.add(4, "five"); 
     words.add(5, "six"); 
     words.add(6, "seven"); 
     words.add(7, "eight"); 
     words.add(8, "nine"); 
     words.add(9, "ten"); 

     ArrayAdapter<String> itemsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, words); 

     ListView listView = (ListView) findViewById(R.id.list); 

     listView.setAdapter(itemsAdapter); 
    } 
} 

XML(含修改):

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/list" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="16dp" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 
android:paddingTop="16dp" 
tools:context="com.example.android.miwok.NumbersActivity"/> 

我對仿真結果如下:

Image_Simulator

+0

謝謝Rafaela,這是我的錯 –