我从json response.for将值填充到ListView中,因为我在运行代码时创建了一个ArrayAdapter,它会抛出错误,如下所示。
08-08 19:06:39.939 28394-28394/com.inspirenetz.app.inpartner E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.inspirenetz.app.inpartner, PID: 28394
android.view.InflateException: Binary XML file line #19: 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.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.inspirenetz.app.inpartner.adapter.RedemptionRequestListViewAdapter.getView(RedemptionRequestListViewAdapter.java:35)
at android.widget.AbsListView.obtainView(AbsListView.java:2306)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
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:16820)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16820)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:610)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:677)
at android.view.View.measure(View.java:16820)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:940)
at android.view.View.measure(View.java:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
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:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
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:16820)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5156)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2294)
at android.view.View.measure(View.java:16820)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1969)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1162)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1348)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1049)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5899)
at android.view.Choreographer$Callb
这里是我的适配器代码
public class RedemptionRequestListViewAdapter extends ArrayAdapter<RedemptionRequestResource> {
private final Context context;
private List<RedemptionRequestResource> objects;
public RedemptionRequestListViewAdapter(Context context, int textViewResourceId, List<RedemptionRequestResource> objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.objects = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.redemption_request_listview, parent, false);
TextView lblRedemptionDate =(TextView)rowView.findViewById(R.id.lblRedemptionDate);
TextView lblTrackingId =(TextView)rowView.findViewById(R.id.lblTrackingId);
TextView lblLoyaltyId =(TextView)rowView.findViewById(R.id.lblLoyaltyId);
TextView lblRedemptionStatus =(TextView)rowView.findViewById(R.id.lblRedemptionStatus);
RedemptionRequestResource redemptionRequestResource = objects.get(position);
lblRedemptionDate.setText(redemptionRequestResource.getRdmDate());
lblTrackingId.setText(redemptionRequestResource.getRdmUniqueBatchTrackingId());
lblLoyaltyId.setText(redemptionRequestResource.getRdmLoyaltyId());
lblRedemptionStatus.setText(redemptionRequestResource.getRdmStatus());
return rowView;
}
}
这是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/customersearch_bg"
tools:context="com.inspirenetz.app.inpartner.redemption.RedemptionRequestListFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblRedemptionDate"
android:text="Redemption Date"
android:textSize="20sp"
style="@style/EditTextDarkTheme"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblTrackingId"
android:text="Tracking ID"
android:textSize="20sp"
style="@style/EditTextDarkTheme"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loyalty ID :"
android:textSize="20sp"
style="@style/EditTextDarkTheme"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblLoyaltyId"
android:text="Loyalty ID"
android:textSize="20sp"
style="@style/EditTextDarkTheme"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status :"
android:textSize="20sp"
style="@style/EditTextDarkTheme"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblRedemptionStatus"
android:text="Status"
android:textSize="20sp"
style="@style/EditTextDarkTheme"/>
</LinearLayout>
</LinearLayout>
表示此行数组适配器中的错误
View rowView = inflater.inflate(R.layout.redemption_request_listview, parent, false);
任何人都可以帮助我。
答案 0 :(得分:1)
我没有足够的声誉来发表评论,但我怀疑您的问题出在您的.axml布局文件中。你能告诉我们这个档案吗?
特别是检查第19行,因为您的日志说这是错误发生的地方。
答案 1 :(得分:0)
我认为你应该使用:
LayoutInflater inflater=((Activity)context).getLayoutInflater()