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

标签 android sdk

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

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: 布局背景细节

    <?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;
    }
}

最佳答案

从您的 LogCat,发现错误。

android.view.InflateException:二进制 XML 文件第 0 行:错误膨胀类 android.widget.ImageView

你可以检查你的图像文件是在 Drawable 还是 Drawable-24

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

可以从 Here 阅读我的答案

关于android - 将 minSdkVersion(21) 更改为 (18) < 设备的 API (19) 但项目停止运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50407227/

相关文章:

android - 如何在 Qt (QML) 应用程序中使用适用于 Android 的 Tensorflow?

android - 磨损项目-attr 'android:windowSwipeToDismiss'

php - 亚马逊简单队列服务 (SQS)

c++ - VK_ERROR_INCOMPATIBLE_DRIVER 与 Mac OS 和 Vulkan MoltenVK

android - 线程 "main"java.lang.UnsatisfiedLinkError : no swt-win32-3550 中的异常

Android:如何将相机结果保存到私有(private)文件

android - 如何从设计支持 android 在选项卡布局中嵌入字体

android - 垂直翻转 Android Canvas

android - 如何在 Windows 7 的模拟器上安装 facebook api?

android - 如何解决com.android.ide.common.internal.LoggedErrorException