Android开发中遇到的一些问题!

  1. 编译报错The android.dexOptions.incremental property is deprecated and it has no effect on the build process.
    android.dexOptions.incremental属性已被弃用,它对构建过程没有影响。
    解决办法:
    app的build.gradle修改

    dexOptions {
    // incremental true //这一行注掉或者删掉
    javaMaxHeapSize “4g”
    }

2.场景:创建类继承IntentService,子类没有无参的构造方法。运行时报错java.lang.InstantiationException
解决办法:
IntentService 是继承自 Service 并处理异步请求的一个类。Service是四大组件之一,我们无法进行手动实例化,实例化是系统来进行的。而且系统是用参数为空的构造函数来实例化Service的,在无参构造方法中调用super(“name”)来进行创建。所以继承IntentService必须创建一个无参的构造方法。

  public MyIntentService() {
        super("MyIntentService");
    }

3.场景:创建recycleview的adapter时,初始化adapter布局的时候报错:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
解决办法:
@Override public PictureHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_picture, parent); return new PictureHolder(view); }
改为

@Override
    public PictureHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_picture, null);
        return new PictureHolder(view);
    }`

parent置为为null

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值