如果我尝试使用包含任何内容的数组更新ListView,我会在二进制XML文件行#8上收到错误。这就是'片段'元素开始,只要我不尝试更新我的ListView,它运行正常。
错误:
02-11 04:12:58.818 8311-8311/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kit.myapplication, PID: 8311
android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:369)
at android.widget.AbsListView.obtainView(AbsListView.java:2346)
at android.widget.ListView.makeAndAddView(ListView.java:1875)
at android.widget.ListView.fillDown(ListView.java:702)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1670)
at android.widget.AbsListView.onLayout(AbsListView.java:2148)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.TableLayout.onLayout(TableLayout.java:445)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.vi
(activity_maps.xml):
<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"
tools:context=".MapActivity"
android:id="@+id/Frame">
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scrollbars="vertical"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_gravity="center_horizontal|top" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="bottom">
<ListView
android:layout_width="wrap_content"
android:layout_height="254dp"
android:choiceMode="none"
android:id="@+id/testList" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawable="@drawable/round_shape_button"
android:text="@string/lookupButton"
android:id="@+id/lookupButton"
android:onClick="onClick" />
</TableLayout>
<TextView
android:layout_width="303dp"
android:layout_height="180dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:text="@string/pleasewaitforgps"
android:id="@+id/textView"
android:layout_gravity="center"
android:textColor="#c8ffffff"
android:textSize="30dp"
android:textIsSelectable="false"
android:textStyle="bold"
android:background="#c9000000"
android:enabled="false"
android:visibility="invisible" />
<FrameLayout
android:layout_width="332dp"
android:layout_height="447dp"
android:layout_gravity="center"
android:background="#ffffff"
android:id="@+id/addressFrame"
android:visibility="invisible">
<TextView
android:layout_width="303dp"
android:layout_height="422dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:text="@string/addressString"
android:id="@+id/addressLabel"
android:layout_gravity="center"
android:textColor="#000000"
android:textSize="25dp"
android:textIsSelectable="false"
android:textStyle="bold"
android:enabled="false"
android:visibility="visible" />
</FrameLayout>
</FrameLayout>
相关守则:
private ListView mListView;
ArrayList<String> mListItems = new ArrayList<String>();
ArrayAdapter<String> mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.activity_maps);
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mListView = (ListView) findViewById(R.id.testList);
mAdapter = new ArrayAdapter<String>(this, R.layout.activity_maps, mListItems);
mListItems.add("anything");
mListView.setAdapter(mAdapter);
更新:添加了完整的XML
答案 0 :(得分:3)
等待。为什么使用活动布局作为列表视图布局?
setContentView(R.layout.activity_maps);
mAdapter = new ArrayAdapter<String>(this, R.layout.activity_maps, mListItems);
我认为问题在于您的ArrayAdapter尝试从xml布局创建其视图。
mAdapter = new ArrayAdapter(this,R.layout.activity_maps, mListItems);
您想要制作什么类型的ListView布局?
如果列表视图项只需要单行文本,则可以使用Android创建的布局。
new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
答案 1 :(得分:0)
您在arrayadapter中使用了错误的布局
更改您的
mAdapter = new ArrayAdapter<String>(this, R.layout.activity_maps, mListItems);
到
mAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, mListItems);