Android基础--Android Studio报错信息:Can only use lower 16 bits for requestCode

Caused by: java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode

 startActivityForResult(intent, R.id.scan);
1
startActivityForResult(Intent intent, int requestCode) 
以上我的代码是以R.id.R.id.scan作为requestCode的值,这个值是超过了16字节数

原因是RequestCode不能为负值,也不能大于16位bit值65536

判断RequestCode的源码:

@Override  
    public void startActivityForResult(Intent intent, int requestCode) {  
        if (requestCode != -1 && (requestCode&0xffff0000) != 0) {  
            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");  
        }  
        super.startActivityForResult(intent, requestCode);  
    }  
--------------------- 
作者:程序人生a 
来源:CSDN 
原文:https://blog.csdn.net/android_it/article/details/51983413 

你可能感兴趣的:(andriod开发,报错处理)