android 开发常见错误汇总系列

1Android 异常 TransactionTooLargeException


今天查看异常报告,发下小米手机7.1.1有一个TransactionTooLargeException 异常,问了一下度娘,发现导致这个异常的原因有很多,不过根本原因就是The Binder transaction failed because it was too large. 就是传递的东西太多了。见官网 https://developer.android.com/reference/android/os/TransactionTooLargeException.html

从这里可以看出The Binder transaction buffer has a limited fixed size, currently 1Mb 传值有1M的限制。我去定位了一下,发现代码就传了三个值,int,int,boolen ,纠结一会,最后发现在onsaveinstancestate(Bundle outstate)方法中有一个putparcelableArraylist(),导致bundle 数值过大,在跳转到的activity中再加上传的三个参数,导致超过1M, 不过,其他的手机却没有这个问题,估计其他手机系统定制后bundle范围有变大的缘故。

产生这种问题原因:

When you get this exception in your application, please analyze your code.

  1. Are you exchanging lot of data between your services and application?
  2. Using intents to share huge data, (for example, the user selects huge number of files from gallery share press share, the URIs of the selected files will be transferred using intents)
  3. receiving bitmap files from service
  4. waiting for android to respond back with huge data (for example, getInstalledApplications() when the user installed lot of applications)
  5. using applyBatch() with lot of operations pending

How to handle when you get this exception

If possible, split the big operation in to small chunks, for example, instead of calling applyBatch() with 1000 operations, call it with 100 each.

Do not exchange huge data (>1MB) between services and application

记录一下。


2, UnsatisfiedLinkError: dlopen failed: cannot locate symbol “strtof” referenced by “libsupportjni.so” on API <20,

cannot locate symbol "__isnanf" referenced by "libsupportjni.so"..(vivo 4.2.2)

问题解决办法 Go to Run -> Edit Configurations -> Profiling, and disable "Enable advanced profiling". This feature is not currently compatible with API <20, and will cause this or similar crashes. This may be fixed in the future, but as of Android Studio 2.4 preview 7, it's an open issue.

3,Android调试打断点和不打断点执行结果不一致问题解决

今天开发中从状态栏的消息点击进入到相应activity页面,有的手机可以,有的手机不行。后来打断点调试发现,打断点后可以进入,然而不打断点后反而不能进入。不断测试结果都是这样,由此判断有可能是因为此方法在执行的时候所需要的参数在获取的时候需要一段时间,而debug的时候是一步一步执行代码,时间很充足,而当程序正常执行的时候由于执行的时间很快,某一个或一些参数没有获取到就直接执行了此方法,由此导致执行结果就会出现和debug时候的执行结果不一致的问题,针对这样的问题有一个解决方法,就是在执行这个方法之前让程序停一会儿,给获取需要的参数所执行的代码足够的时间。

//现场休眠1000毫秒(作用是使当前线程暂时睡眠指定的时间)
Thread.sleep(1000);  

4, java.lang.NullPointerException

Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object referencecom.xianglin.app.biz.discovery.recommend.RecommendFragment$4.run(RecommendFragment.java:272)

解决办法:

if (mActivity == null)return; //这里空判断
new Handler().postDelayed(new Runnable() {
    public void run() {
        if (mActivity != null){
            videoRefreshNum.startAnimation(AnimationUtils.loadAnimation(mActivity, R.anim.anim_slide_out_from_top));
            videoRefreshNum.setVisibility(View.GONE);
        }

    }
}, SHOW_TIME);

5,java.lang.IllegalStateException:ViewStub must have a non-null ViewGroup viewParent  

原因:但因为viewstub只能inflate一次(setVisibility也会间接调用inflate),重复inflate则会报异常

解决方法为设置一个Boolean类型的变量,标记viewstub是否已经inflate,如果viewstub还未inflate则执行初始化操作,反之则不进行操作。其中要使用ViewStub中的OnInflateListener()监听事件来判断是否已经填充。

mViewStub = (ViewStub)findViewById(R.id.viewstub_match_single); mViewStub.setOnInflateListener(new OnInflateListener() { @Override public void onInflate(ViewStub stub, View inflated) { isInflate = true; } });

private void initViewStub(){//填充ViewStub的方法 if(!isInflate){//如果没有填充则执行inflate操作 View view = stubMatchSingle.inflate(); //初始化ViewStub的layout里面的控件 TextView mTv = (TextView) view.findViewById(R.id.txt_url); mTv.setOnClickListener(this); } }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值