将minSdkVersion(21)改为(18)<设备的API(19)但项目停止运行

时间:2018-05-18 08:43:25

标签: android sdk

我的真实设备是API(19),我读了一些帖子并从21更改了minkSdkVersion

minSdkVersion 21

到18

minSdkVersion 18 

同步项目并运行,但我的项目停止运行。谁知道为什么? (据说对不起,音乐已经停止了)

编辑:这是Logcat所说的,请不要告诉我一些代码只适用于SdkVerson 21 :(

05-18 16:24:43.031 11745-11745/com.bkav.demo.music E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bkav.demo.music, PID: 11745
android.view.InflateException: Binary XML file line #0: Error inflating class android.widget.ImageView
    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 com.bkav.demo.music.AdapterBaiHat.getView(AdapterBaiHat.java:61)
    at android.widget.AbsListView.obtainView(AbsListView.java:2338)
    at android.widget.ListView.measureHeightOfChildren(ListView.java:1273)
    at android.widget.ListView.onMeasure(ListView.java:1182)
    at android.view.View.measure(View.java:16851)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:794)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:544)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5374)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2368)
    at android.view.View.measure(View.java:16851)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2246)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1312)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
    at android.view.Choreographer.doCallbacks(Choreographer.java:591)
    at android.view.Choreographer.doFrame(Choreographer.java:560)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    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:828)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
    at dalvik.system.NativeStart.m

编辑3: Layout_background_detail

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_marginTop="80dp"
        android:layout_marginBottom="90dp"
        android:layout_height="match_parent"
        >

        <ImageView
            android:id="@+id/hinhnen"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/anhth"
            />

</FrameLayout>

AdapterBaiHat:

    package com.bkav.demo.music;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;


public class AdapterBaiHat extends BaseAdapter {

    private Context context;
    private int resource;
    private ArrayList<ThongTinBaiHat> arrayList;


    public AdapterBaiHat(Context context, int resource, ArrayList<ThongTinBaiHat> arrayList) {
        this.context = context;
        this.resource = resource;
        this.arrayList = arrayList;
    }

    private class ViewHolder{
        private TextView mSoThuTu;
        private TextView mTenBaHat;
        //private TextView mTheLoai;
        private TextView mTime;
        private ImageView mOther;

    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if(view == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(resource,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.mSoThuTu = view.findViewById(R.id.number);
            viewHolder.mTime = view.findViewById(R.id.time);
            viewHolder.mTenBaHat = view.findViewById(R.id.name_song);
            //viewHolder.mTheLoai  = view.findViewById(R.id.detail);
            viewHolder.mOther = view.findViewById(R.id.other);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        final ThongTinBaiHat thongTinBaiHat = arrayList.get(i);

        viewHolder.mTenBaHat.setText(thongTinBaiHat.getTenBaiHat());
        viewHolder.mTime.setText(thongTinBaiHat.getThoigian());
        //viewHolder.mTheLoai.setText(thongTinBaiHat.getTheloai());
        viewHolder.mSoThuTu.setText("" + thongTinBaiHat.getSothutu());
        viewHolder.mOther.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PopupMenu popupMenu =  new PopupMenu(context,viewHolder.mOther);
                popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());

                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        Toast.makeText(context,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
                        return true;
                    }
                });

                popupMenu.show();
            }
        });

        return view;
    }
}

1 个答案:

答案 0 :(得分:1)

从您的LogCat中找到错误。

android.view.InflateException: Binary XML file line #0: Error inflating class android.widget.ImageView

你可以查看你的图片文件,无论它是Drawable还是Drawable-24

如果它在Drawable-24中,移动到drawable文件。

可以从Here

阅读我的ans