以下是我在执行程序时遇到的错误。我尝试了一些在堆栈溢出时给出的解决方案,但我无法弄清楚问题。有人可以帮助我吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/contact_card"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:weightSum="1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_weight="0.8"
android:layout_gravity="start"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/name"
android:textSize="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/phone_number"
android:textSize="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:contentDescription="@string/call_description"
android:id="@+id/call_button"
android:src="@drawable/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
&#13;
package com.example.kalap.contacts_ttm.adapters;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.kalap.contacts_ttm.R;
import com.example.kalap.contacts_ttm.objects.Contact;
import java.util.ArrayList;
/**
* Created by kalap on 20-03-2016.
*/
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ContactViewHolder> {
private ArrayList<Contact> contactList;
private Activity activity;
private Context context;
public ContactAdapter(ArrayList<Contact> contactList, Activity activity) {
this.contactList = contactList;
this.activity = activity;
this.context = activity.getApplicationContext();
}
@Override
public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.custom_contact_row, parent, false);
return new ContactViewHolder(view);
}
@Override
public void onBindViewHolder(ContactViewHolder holder, final int position) {
holder.name.setText(contactList.get(position).getName());
holder.phoneNumber.setText(contactList.get(position).getPhoneNumber());
holder.callButton.setOnClickListener(new ImageView.OnClickListener() {
@Override
public void onClick(View view) {
if(contactList.get(position).getPhoneNumber().isEmpty()) {
Snackbar.make(view,"Phone number does not exist",Snackbar.LENGTH_LONG).show();
} else {
Intent call = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + contactList.get(position).getPhoneNumber()));
try {
activity.startActivity(call);
} catch (SecurityException e) {
Log.e("TTM_Error", e.getMessage());
Snackbar.make(view,"Permission to call not given",Snackbar.LENGTH_LONG).show();
}
}
}
});
}
@Override
public int getItemCount() {
return contactList.size();
}
public class ContactViewHolder extends RecyclerView.ViewHolder {
private TextView name;
private TextView phoneNumber;
private ImageView callButton;
private CardView contactCard;
public ContactViewHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.name);
phoneNumber = (TextView) itemView.findViewById(R.id.phone_number);
callButton = (ImageView) itemView.findViewById(R.id.call_button);
contactCard = (CardView) itemView.findViewById(R.id.contact_card);
}
}
}
&#13;
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kalap.contacts_ttm, PID: 955
android.view.InflateException: Binary XML file line #21: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.example.kalap.contacts_ttm.adapters.ContactAdapter.onCreateViewHolder(ContactAdapter.java:39)
at com.example.kalap.contacts_ttm.adapters.ContactAdapter.onCreateViewHolder(ContactAdapter.java:25)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5464)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4689)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4599)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1988)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1384)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3003)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2600)
at android.view.View.measure(View.java:16508)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
at android.view.View.measure(View.java:16508)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16508)
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:16508)
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:16508)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1955)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1152)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1334)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1039)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5648)
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
&#13;
答案 0 :(得分:0)
问题已解决,它发生在TextView中给出的textSize,即?Android。我删除了它们并对大小进行了硬编码以解决问题。