android.view.InflateException:二进制XML文件行#8:二进制XML 文件行#8:膨胀类android.support.v7.widget.CardView时出错 原因:android.view.InflateException:二进制XML文件第8行:错误膨胀了类android.support.v7.widget.CardView 原因:java.lang.ClassNotFoundException:在路径:DexPathList [[zip文件]中找不到类“ android.support.v7.widget.CardView” zip文件“ /system/framework/org.apache.http.legacy.boot.jar” “ /data/app/com.hfad.bitsandpizzas-pFsCVGHBTBShhdbfE75xtw==/base.apk"],nativeLibraryDirectories=[/data/app/com.hfad.bitsandpizzas-pFsCVGHBTBShhdbfE75xtw==/lib/x86, / system / lib]] 在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) 在java.lang.ClassLoader.loadClass(ClassLoader.java:379) 在java.lang.ClassLoader.loadClass(ClassLoader.java:312) 在android.view.LayoutInflater.createView(LayoutInflater.java:606) 在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 在android.view.LayoutInflater.rInflate(LayoutInflater.java:863) 在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 在android.view.LayoutInflater.inflate(LayoutInflater.java:515) 在android.view.LayoutInflater.inflate(LayoutInflater.java:423) 在com.hfad.bitsandpizzas.data.NearbyGreetRecyclerViewAdapter.onCreateViewHolder(NearbyGreetRecyclerViewAdapter.java:39) 在com.hfad.bitsandpizzas.data.NearbyGreetRecyclerViewAdapter.onCreateViewHolder(NearbyGreetRecyclerViewAdapter.java:25) 在android.support.v7.widget.RecyclerView $ Adapter.createViewHolder(RecyclerView.java:6411) 在android.support.v7.widget.RecyclerView $ Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5597) 在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5482) 在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5478) 在android.support.v7.widget.LinearLayoutManager $ LayoutState.next(LinearLayoutManager.java:2215) 在android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1542) 在android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1502) 在android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595) 在android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3625) 在android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3354) 在android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3886) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:1197) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.support.v4.view.ViewPager.onLayout(ViewPager.java:1766) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131) 在android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) 在android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1389) 在android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:868) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) 在android.widget.FrameLayout.onLayout(FrameLayout.java:261) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) 在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) 2018-11-03 20:17:21.037 7084-7084 / com.hfad.bitsandpizzas E / AndroidRuntime:位于 android.widget.LinearLayout.onLayout(LinearLayout.java:1565) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) 在android.widget.FrameLayout.onLayout(FrameLayout.java:261) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) 在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) 在android.widget.LinearLayout.onLayout(LinearLayout.java:1565) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) 在android.widget.FrameLayout.onLayout(FrameLayout.java:261) 在com.android.internal.policy.DecorView.onLayout(DecorView.java:753) 在android.view.View.layout(View.java:20672) 在android.view.ViewGroup.layout(ViewGroup.java:6194) 在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792) 在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319) 在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460) 在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:7183) 在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:949) 在android.view.Choreographer.doCallbacks(Choreographer.java:761) 在android.view.Choreographer.doFrame(Choreographer.java:696) 在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:935) 在android.os.Handler.handleCallback(Handler.java:873) 在android.os.Handler.dispatchMessage(Handler.java:99) 在android.os.Looper.loop(Looper.java:193) 在android.app.ActivityThread.main(ActivityThread.java:6669) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
GreetFragment
package com.hfad.bitsandpizzas;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v7.widget.LinearLayoutManager;
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.ArrayAdapter;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.hfad.bitsandpizzas.Util.Constants;
import com.hfad.bitsandpizzas.Util.MapJSONToModel;
import com.hfad.bitsandpizzas.data.NearbyGreetRecyclerViewAdapter;
import com.hfad.bitsandpizzas.model.Gang;
import com.hfad.bitsandpizzas.model.Greet;
import com.hfad.bitsandpizzas.model.NearbyGreet;
import com.hfad.bitsandpizzas.model.User;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A simple {@link Fragment} subclass.
*/
public class GreetFragment extends Fragment {
private RecyclerView recyclerView;
private NearbyGreetRecyclerViewAdapter nearbyGreetRecyclerViewAdapter;
private List<NearbyGreet> nearbyGreets = new ArrayList<>();
private RequestQueue queue;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_greets, container, false);
queue = Volley.newRequestQueue(inflater.getContext());
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(inflater.getContext()));
nearbyGreets = getNearbyGreets();
nearbyGreetRecyclerViewAdapter = new NearbyGreetRecyclerViewAdapter(inflater.getContext(), nearbyGreets);
recyclerView.setAdapter(nearbyGreetRecyclerViewAdapter);
nearbyGreetRecyclerViewAdapter.notifyDataSetChanged();
return rootView;
}
//Get movies
public List<NearbyGreet> getNearbyGreets() {
nearbyGreets.clear();
JsonArrayRequest jsonObjectRequest = new JsonArrayRequest(Request.Method.GET,
Constants.URL, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
for (int i = 0; i < response.length(); i++) {
JSONObject parent = response.getJSONObject(i);
JSONObject greetJSON = parent.getJSONObject("greet");
Greet greet = MapJSONToModel.mapJSONToGreet(greetJSON);
JSONObject userJSON = greetJSON.getJSONObject("user");
User user = MapJSONToModel.mapJSONToUser(userJSON);
greet.setUser(user);
if (greetJSON.has("gang") && !greetJSON.isNull("gang")) {
JSONObject gangJSON = greetJSON.getJSONObject("gang");
Gang gang = MapJSONToModel.mapJSONToGang(gangJSON);
greet.setGang(gang);
}
NearbyGreet nearbyGreet = new NearbyGreet();
nearbyGreet.setGreet(greet);
nearbyGreet.setDistance(BigDecimal.valueOf(parent.getDouble("distance")));
nearbyGreets.add(nearbyGreet);
}
nearbyGreetRecyclerViewAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("Content-Type", "application/json");
params.put("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTU0Mzg0ODExM30.Hj4b3kvZvg_XpRGqYGWrIfZVv3Cnt5kwHXG1YdSdhCga_BXuP_BLFAR3eLB1gU3q6-QLqTAuyrCAmEHSY3Fgiw");
return params;
}
@Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
};
queue.add(jsonObjectRequest);
return nearbyGreets;
}
}
NearbyGreetRecyclerViewAdapter
package com.hfad.bitsandpizzas.data;
import android.content.Context;
import android.content.Intent;
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 android.widget.Toast;
import com.hfad.bitsandpizzas.R;
import com.hfad.bitsandpizzas.model.Greet;
import com.hfad.bitsandpizzas.model.NearbyGreet;
import com.squareup.picasso.Picasso;
import java.util.List;
public class NearbyGreetRecyclerViewAdapter extends RecyclerView.Adapter<NearbyGreetRecyclerViewAdapter.ViewHolder>{
private Context context;
private List<NearbyGreet> nearbyGreets;
public NearbyGreetRecyclerViewAdapter(Context context, List<NearbyGreet> nearbyGreets) {
this.context = context;
this.nearbyGreets = nearbyGreets;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.greet_row, parent, false);
return new ViewHolder(view, context);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
NearbyGreet nearbyGreet = nearbyGreets.get(position);
holder.title.setText(nearbyGreet.getGreet().getTitle());
Log.e("hehy", String.valueOf(nearbyGreets.size()));
}
@Override
public int getItemCount() {
return nearbyGreets.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
TextView title;
public ViewHolder(View itemView, final Context ctx) {
super(itemView);
context = ctx;
title = (TextView) itemView.findViewById(R.id.greetTitleID);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Movie movie = movieList.get(getAdapterPosition());
//Intent intent = new Intent(context, MovieDetailActivity.class);
//intent.putExtra("movie", movie);
//ctx.startActivity(intent);
}
});
}
@Override
public void onClick(View v) {
}
}
}
答案 0 :(得分:0)
确保将cardview-v7
依赖项添加到build.gradle
中。
build.gradle
dependencies {
// Other dependencies ...
implementation "com.android.support:cardview-v7:28.0.0"
}