java值byte类型长度超出

org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache. 在xml文件中碰到这样的报错的时候,有可能是你在里面使用了这种注释,编译会报错,可能这就是约定大于配置 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='id', mode=IN 阅读详情

本人遇到的问题是mysql字段定义的是tinyint(3) unsigned  对应的java里面的是byte。 

一、遇到的问题是这样的:

[RemoteTestNG] detected TestNG version 6.9.10
log4j: Parsing for [root] with value=[DEBUG,D,E,stepLog].
log4j: Level token is [DEBUG].
log4j: Category root set to DEBUG
log4j: Parsing appender named "D".
log4j: Parsing layout options for "D".
log4j: Setting property [conversionPattern] to [%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n].
log4j: End of parsing for "D".
log4j: Setting property [append] to [true].
log4j: Setting property [threshold] to [DEBUG].
log4j: Setting property [file] to [logs/logs.log].
log4j: setFile called: logs/logs.log, true
log4j: setFile ended
log4j: Appender [D] to be rolled at midnight.
log4j: Parsed "D" options.
log4j: Parsing appender named "E".
log4j: Parsing layout options for "E".
log4j: Setting property [conversionPattern] to [%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n].
log4j: End of parsing for "E".
log4j: Setting property [append] to [true].
log4j: Setting property [threshold] to [ERROR].
log4j: Setting property [file] to [logs/error.log].
log4j: setFile called: logs/error.log, true
log4j: setFile ended
log4j: Appender [E] to be rolled at midnight.
log4j: Parsed "E" options.
log4j: Parsing appender named "stepLog".
log4j: Parsing layout options for "stepLog".
log4j: Setting property [conversionPattern] to [%m%n].
log4j: End of parsing for "stepLog".
log4j: Setting property [file] to [logs/stepLog.log].
log4j: Setting property [append] to [true].
log4j: Setting property [threshold] to [INFO].
log4j: setFile called: logs/stepLog.log, true
log4j: setFile ended
log4j: Appender [stepLog] to be rolled at midnight.
log4j: Parsed "stepLog" options.
log4j: Finished configuring.
[TestNG] Running:
C:\Users\lenovo\AppData\Local\Temp\testng-eclipse-1408996642\testng-customsuite.xml

Begin executing test method[com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest . Coupon_Coupon_getCouponList_test ()] in thread[1].

Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
PooledDataSource forcefully closed/removed all connections.
Opening JDBC Connection
Created connection 1877986974.
Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@6fefce9e]
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'type' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
### The error may exist in com/xes/qa/apitest/jcsj/db/mapper/Xes_couponsMapper.java (best guess)
### The error may involve com.xes.qa.apitest.jcsj.db.mapper.Xes_couponsMapper.getcouponList
### The error occurred while handling results
### SQL: SELECT id,name,code,type,valid_start_date,valid_end_date,face_value,order_full_price,receive_type,num,receive_start_time,receive_stime,receive_end_time,receive_etime, `status`,description,creater_id,create_time,modify_time FROM xes_coupons WHERE `receive_type` = 7 AND `status` = 3 AND `valid_start_date` <= SYSDATE() AND `valid_end_date` >= SYSDATE() AND `receive_stime` <= unix_timestamp(now()) AND `receive_etime` >= unix_timestamp(now()) ORDER BY `face_value` DESC, `id` DESC;
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'type' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy25.getcouponList(Unknown Source)
at com.xes.qa.apitest.jcsj.db.dbutils.DbUtils.getXesCoupuonsList(DbUtils.java:43)
at com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest.Coupon_Coupon_getCouponList_test(CouponCouponGetCouponListTest.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197)
at org.simfast.simpletester.unitils.SimpleTesterTestNG.run(SimpleTesterTestNG.java:244)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'type' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:68)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:434)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:344)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:298)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:273)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:246)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:160)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
... 34 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '4' is outside valid range for the datatype TINYINT.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.Util.getInstance(Util.java:387)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
at com.mysql.jdbc.ResultSetImpl.throwRangeException(ResultSetImpl.java:7091)
at com.mysql.jdbc.ResultSetImpl.getByteFromString(ResultSetImpl.java:1712)
at com.mysql.jdbc.ResultSetImpl.getByte(ResultSetImpl.java:1659)
at com.mysql.jdbc.ResultSetImpl.getByte(ResultSetImpl.java:1671)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:68)
at com.sun.proxy.$Proxy28.getByte(Unknown Source)
at org.apache.ibatis.type.ByteTypeHandler.getNullableResult(ByteTypeHandler.java:37)
at org.apache.ibatis.type.ByteTypeHandler.getNullableResult(ByteTypeHandler.java:26)
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:66)
... 48 more
Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@6fefce9e]
Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@6fefce9e]
Returned connection 1877986974 to pool.
[Failed] CouponCouponGetCouponListTest.Coupon_Coupon_getCouponList_test(org.simfast.simpletester.core.TestData)[pri:0, instance:com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest@5e316c74]
Report directory is :D:\sourcecode\new-test\target\SimpleTester
PooledDataSource forcefully closed/removed all connections.
FAILED: Coupon_Coupon_getCouponList_test(org.simfast.simpletester.core.TestData@d278d2b)
java.lang.NullPointerException
at com.xueersi.qa.continuation.testcase.CouponCouponGetCouponListTest.Coupon_Coupon_getCouponList_test(CouponCouponGetCouponListTest.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197)
at org.simfast.simpletester.unitils.SimpleTesterTestNG.run(SimpleTesterTestNG.java:244)
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 6 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@77b52d12: 6 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@15975490: 5 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@4157f54e: 3 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@735f7ae5: 16 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@2c6a3f77: 19 ms

之前调通的代码一运行突然报了这样一堆的错,出错了不要紧看下问题出在哪里,于是仔细观察一番之后发现了这一堆报错中的关键信息,如下:

 

确定问题之后就到代码中去看看呗,代码如下:

mapper里面配置的代码如下:

 

model里面对应数据库字段的代码如下:

看来看去很简单的代码嘛,没什么错,这时候想到去数据库里看看吧

询问研发老师,果然这里的字段他们调整了,增加了101,102,255,看到255再回去看报错也是跟255有关系的,基本可以确定问题引发的原因了。

那么怎么解决呢?

二、解决办法


要解决问题得先理解下错误的具体原因:

1. 网上查询资料对jdbcType这个参数的描述不多,作用不清楚,大概的意思是“jdbcType这个参数的应用场景就是,当执行mapping文件的时候,有个映射的参数为空,那么无法确定他的类型,这个时候就需要jdbcType来确定类型“。

2. 既然jdbc Type是备用的那就不考虑调整了,于是解决思路放到了model里面的java代码上,获取到的资料如下:

    mysql中的tinyint和java中的byte的数值范围是一样的(-128~127),如果你能保证自己存储的数值不会超过这个最大值是可以的,而且tinyint只有1字节。

   既然数据库使用tinyint,肯定取值在tinyint的范围内。结果映射的时候是可以指定javaType的。 没必要使用默认的byte,完全可以用int,Integer。

 看到这里基本就确定了问题的解决办法,其实就是byte类型是-128~127,而开发在库中新加入的255超出了这个范围所以导致出错,因此修改model代码如下:

 

调整完成再运行,果然问题解决了。

Java byte 类型用法集合 throw new IllegalArgumentException("byte数组必须不为空,并且是2位!throw new IllegalArgumentException("byte数组必须不为空,并且是8位!throw new IllegalArgumentException("byte数组必须不为空,并且是2位!throw new IllegalArgumentException("byte数组必须不为空,并且是4位!结果是int,但是符号位是0,说明是正数,最后就是正整数234. 阅读详情

相关推荐

STM32驱动AD7779:双极性电源下8通道同步ADC的SPI配置与数据采集实战

本文详细介绍了在双极性电源供电下,使用STM32通过SPI接口驱动AD7779同步ADC芯片实现8通道高精度数据采集的实战经验。重点解析了电源设计、抗干扰处理、寄存器配置、SPI通信技巧及数据校准方法,帮助工程师解决工业测量中的同步采样与噪声控制难题。

e3f4g5的博客 370

idea运行Mybatis项目出现的常见错误(编码错误等)

java.lang.ExceptionInInitializerError....The error may exist in UserMapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource UserMapper.xml

静水流深,沧笙踏歌 6656

xctf攻防世界 MISC高手进阶区 low

1. 进入环境,下载附件 给出的一张bmp图片,没有其他信息 2. 问题分析 扔进binwalk中,没有发现有用信息 使用zsteg,没有有用信息 塞入StegSolve中,发现有点猫腻,如图: 有点二维码的感觉,emmm,需要像素处理,但不知道如何下手,参考网上的wp,发现是让使用lsb隐写,copy代码: from PIL import Image img = Image.open('./pic/low.bmp') img_tmp = img.copy() pix = img_tmp.load()

l8947943的博客 1万+

tinyint对应java中什么类型_Java中的数据类型

Java的数据类型分为基本数据类型和引用数据类型一.基本数据类型:Java语言提供了八种基本类型。六种数字类型(四个整数型,两个浮点型),一种字符类型,还有一种布尔型。byte 数据类型是8位、有符号的,以二进制补码表示的整数;short 数据类型是 16 位、有符号的以二进制补码表示的整数int 数据类型是32位、有符号的以二进制补码表示的整数;long 数据类型是 64 位、有符号的以二进制补...

weixin_39609752的博客 2675

立创EDA开源足轮机器人:基于STM32F407与ESP32的LQR自平衡与FOC驱动设计全解析

本文详细解析了基于立创EDA平台的开源足轮机器人项目。该项目采用STM32F407作为主控,ESP32负责无线通信,并应用LQR自平衡算法与FOC驱动技术,实现了机器人的稳定站立、移动转向及复杂地形适应能力。文章深入剖析了其硬件架构、软件设计及调试经验,为机器人运动控制学习提供了宝贵参考。

weixin_42608299的博客 232

油气井管柱力学发展

油气井管柱力学发展 1 石油管柱力学问题的发复杂性 1)油气管柱动力学的非线性 钻井中钻柱在重力、钻压、扭矩、钻井液浮力和井壁约束等作用下,产生三维变形。一方面随井眼轴线的弯曲而弯曲,这一变形被称为管柱的初位移;另一方面,管柱在运动过程中相对井眼轴线也有变形,这种变形被称为计算位移。管柱大变形主要表现在初位移部分,计算位移相对很小。大曲率井眼中管柱产生大挠度,但管柱很长且柔软性较好,变形一般仍保持...

weixin_43831995的博客 950

MyBatis从入门到精通(十四):在MyBatis中使用类型处理器

最近在读刘增辉老师所著的《MyBatis从入门到精通》一书,很有收获,于是将自己学习的过程以博客形式输出,如有错误,欢迎指正,如帮助到你,不胜荣幸! 本篇博客主要讲解在MyBatis中如何使用类型处理器。 1. 明确需求 在设计之初,sys_role表的enabled字段有2个可选值,其中0 代表禁用,1代表启用,而且实体类中我们使用的是Interger类型: /** * 有效标志 ...

LIU18612105538的博客 333

论文翻译:Automatic Lesson Plan Generation via Large Language Models with Self-critique Prompting

在本文中,我们利用大型语言模型(LLMs)的理解和生成能力来自动生成定制化的课程计划。这解决了传统计划可能无法充分满足不同教学环境和学生群体的特定需求的常见挑战。我们提出了一个新颖的三阶段过程,包括使用检索增强生成(RAG)逐步生成课程计划的每个关键组成部分,通过LLMs进行自我批评,以及随后的细化。我们使用这种方法为小学2至5年级生成了涵盖80多个主题的数学课程计划。邀请了三位经验丰富的教育工作者制定全面的课程计划评估标准,然后使用这些标准将我们的LLM生成的课程计划与同一主题的实际课程计划进行基准比较。

CSPhD-winston的博客 1101

Java数据类型详解

Java数据类型基本数据类型int(整形)long(长整型)double(双精度浮点型)float(浮点型)short(短整型)char(字符型)byte(字节型)boolean(布尔型)注意事项 基本数据类型 int(整形) 整形类型,无论机器型号(因为有JVM,java的所有类型都是固定大小的),整形在java中占四个字节。 其对应的包装类: Integer 取值范围:-2147483648 -> 2147483647,如果赋值超出此范围会报错(如图) long(长整型) 大小:8个字节 对应的

Onen404的博客 763

Android 13.0 app进程保活白名单功能实现

在13.0的系统rom产品开发中,在某些重要的app即使进入后台,产品需求要求也不想被系统杀掉进程,需要app长时间保活,就是app进程保活白名单功能的实现, 所以需要在系统杀进程的时候不杀掉白名单的进程,接下来就看怎么样来实现这些功能

安卓兼职framework和app工程师的博客 3142

还在纠结二层交换机和三层交换机的区别?这篇文章帮你讲明白!

你好,这里是网络技术联盟站,我是瑞哥。公众号后台有小伙伴想要写一篇文章具体介绍一下二层交换机和三层交换机,此类的文章,之前写过几篇,今天瑞哥再写一篇,希望对大家有所帮助!

网络技术联盟站 4441

JAVA byte[]数组转long

最近在搞一个读取数据库日志,然后解析实时日志的程序,发现读取的日志id是number类型,但是得到的记录确实byte类型数组,因为byte类型的最大取值范围是-128到127,所以当number的值超出这个范围时候,byte数组就需要增加长度 byte占一个字节,如果不做处理直接付给int或long类型的变量,当高位为1时会导致得到不正确的值(负数), 如果与0xff(或者0xffL)做位与就可以保证得到byte本身的值。以下是byte和long对应的几个例子: byte[] lo...

beijiaoguzai的博客 4596

Lammps模拟剪切作用下的位错滑移

Lammps模拟位错与障碍物作用。在lammps中实现周期性位错阵列模型模拟剪切作用下1/2刃位错与障碍物的交互作用

Rockyoung 3459

String index out of range: 6 越界问题

一般出现这个问题都发生在数组的获取中,原因是本身一个只有4个元素的数组,你截取了超过他本身就会出现越界的问题。之前刚开始学JAVA的时候有个问题特别的典型,就是把int a=1000 赋值给 byte b=a 就会出现越界的问题。原因就是byte所承受的是-128到127,1000大于了他所能承受的范围,所以越界。 ...

G_whang的博客 1万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Java中两个byte类型相加结果赋值给byte类型的变量会报编译错误,byte加byte的结果为什么是int?

背景: 之前偶然看到有讨论这个问题,在网上搜了半天,结果都不尽如人意,解释没有到位, 有的说byte加byte默认就是int,那为什么这么做呢? 这不是找麻烦么?这种奇怪的默认还有哪些?带来一些列疑问。。。。。。 有的说byte存储的就是整型数据,这种说法的对错姑且不论,至少我觉得难免有点牵强了,还是疑问重重。。 所以今天专门总结一下: -------------------------...

the blog of alunSemiconductor 8694

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

JAVA byte 类型

JAVA byte 类型 不管什么数据,计算机最终存储的是二进制的0和1,每个二进制占1位(bit); 因为最早是老美发明的计算机,英语的所有字符使用8位二进制就能都表征了,所以老美规定了8位等于1字节(byte); 即是最早的ASCII编码; 比如字母a,占用1字节,即8个位的二进制(01),ASCII编码就是0110 0001,二进制对人类不友好,于是用数学里的进制转换,转为十进制的97,十六...

chenzl的专栏 2502

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

java byte数组最大长度是多少

使用eclipse默认的vm arguments,运行以下代码: public static void main(String[] args) { byte[] array=new byte[61858764]; // short[] shortArray=new short[30929382]; // int[] intArray=new int[15464691]; // long[] longArray=new long[7732345]; } 成功,没有报错,可知在eclipse默认的vm argu

岛田悠米 1万+

java中byte和byte类型的变量运算后赋值给byte类型的变量,为什么会报错?

首先我们知道,当byte和int类型的数据进行运算,编译时会把byte的变量的值提升为int类型再进行运算,这是如果你将他们二者的结果赋值给int类型的变量的话,即使没有溢出也会导致报错. 但是我们发现如果两个变量都是byte型的话,仍然会报错 原因可以从两个方面来解释. JVM中没有直接操作byte的指令, 在Java虚拟机中,对于大部分与数据类型相关的字节码指令,他们的操作码助记符中都有特...

i6223671的博客 4773

获取byte的各个bit值_Java中获取一个Byte 的各个Bit的值

在介绍具体方法之前,首先介绍两个概念:位(bit)和字节(byte)。计算机中以二进制来存储数据,二进制共有两个数:0和1。一个0或一个1即为1位。8位即为一个字节,字节为计算机存储空间的基本计量单位。一般,一个英文字符或数字占一个字节,一个汉字占2个字节。在各种语言中,数据类型都占用一定的存储空间,在Java中,各数据类型占用的空间情况如下:数据类型字节数据范围byte1个字节(8位)-128~...

weixin_39627697的博客 1752

Java中byte的符号位

在Java中byte类型是有符号的,而Java中又没有提供无符号的byte类型,因此在其表示范围为-128-127之间。而这样对于一些I/O处理程序来说需要对考虑符号位问题,通常的做法可能是:    int unsignedByte = signedByte >=0 ? signedByte : signedByte + 256;         这里我们发现,由于byte的符号位的关系,我们

jackwofe的专栏 1万+

Java中的byte类型

前言 在一次小项目中,使用了Java与QT进行TCP的通信,Java中只需要将要发送的字节数据写入OutputStream变量,然后write即可发送,但OutputStream.write只接受byte类型数据,若发送一个int数据则需要拆分为4个byte;Java的byte数据范围为-128~127,如果通过移位拆分出的字节变量值大于127,则write时,实际写入的字节为负数;如果接收端使用...

北京-大白的博客 1万+

Java中的byte

最近因为在做金融项目,里面对byte的操作要求比较多,所以在这里整理了一下关于Java中的byte类型。Java虚拟机中没有byte类型恩。。。怎么说呢,个人感觉这个说法有点儿唬人的意思。的确,当这个想法刚刚出现在我的脑海中的时候我觉得也有些胡扯,毕竟byte类型就在那里,怎么能说Java虚拟机中没有byte类型呢?好吧,我来稍稍的解释一下。Java虚拟机对基本类型的操作基本都是在栈上

netHibernate的专栏 3万+

[Java]获取byte数组的实际使用长度

背景:byte.length只能获取到初始化的byte数组长度,而不是实际使用的长度,因此想要获取到实际的使用长度只能靠其他方法实现。 方法一: public class ByteActualLength { public static int returnActualLength(byte[] data) { int i = 0; f...

aew95547的博客 2852

byte数组的实际使用长度

今天在编写java程序时发现了byte数组的一个有趣的现象,那就是当时用new String方式将byte数组转变为String时,byte数组中未被使用的部分('\0')仍然一同被转换为了String 1 byte[] bytes=new byte[1024]; 2 String s=new String(byte[]); 3 System.out.println(bytes...

aomilin4332的博客 1731

Java 任意长度byte数组转换为int数组

嗯。最近工程上遇到一个byte数组转换为int的问题,解决过程中遇到了几个坑,经过各种查资料终于还是解决了。撒花。 Java的位运算以及byte数组与其他类型数据的转换比c/c++感觉麻烦一些。这里简单说明一下byte数组和int的转换吧。 总所周知,int类型数据在Java中占据32 bit,byte占据8 bit,这样的话,正常情况下4个byte可以转换成一个int类型数据。 当然,不正

最萌fb 6086
上一篇: java之mvc接收postman传递list
下一篇: postman上传multipartfile
baicp3
博客等级 码龄16年 69粉丝 282原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值