我尝试在自定义列表中显示数据,但是当我尝试显示数据时出现了膨胀异常,我搜索了很多但没有找到解决方案。
log cat ..
Process: com.example.directory, PID: 19288
android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:121)
at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
at android.widget.AbsListView.obtainView(AbsListView.java:2255)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
下面的是main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/jsonDataListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
以下是main_single_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/sw_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@string/paddingLeft"
android:text="" />
<TextView
android:id="@+id/sw_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@string/paddingLeft"
android:text="" />
<TextView
android:id="@+id/sw_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@string/paddingLeft"
android:text="" />
<TextView
android:id="@+id/sw_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@string/paddingLeft"
android:text="" />
<TextView
android:id="@+id/sw_phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@string/paddingLeft"
android:text="" />
这是我在自定义xml中加载数据的代码示例。
ListView jsons_dta = (ListView) findViewById(R.id.jsonDataListView);
String[] data = { id, name, address, location, phNo };
int[] id = { R.id.sw_id, R.id.sw_name,
R.id.sw_address,R.id.sw_location, R.id.sw_phone };
ListAdapter adpter = new SimpleAdapter(json_data.this, sw_list,
R.layout.single_item_json_data, data, id);
jsons_dta.setAdapter(adpter);
答案 0 :(得分:0)
从dimen更改此get int值而不是字符串。
android:paddingLeft="@string/value"
to
android:paddingLeft="@dimen/xyz"