我正在使用Retrofit + Rxjava从服务器获取实体列表,当我的设计任务失败时,首先检查Internet连接,然后检查与服务器的连接doOnError方法Observable.
当客户端未连接到Internet时,doOnError会在合理的时间内调用并且用户会收到错误消息,但问题是当Internet连接时我得到错误的端口或域(检查服务器问题错误)需要很长时间(约1分钟或更长时间)这真的很烦人.我怎样才能减少这个时间,原因是什么?
public static boolean checkConnection(String ipOrUrl, int port) {
try {
int timeoutMs = 100;
Socket socket = new Socket();
SocketAddress soketAddress = new InetSocketAddress(ipOrUrl, port);
socket.connect(soketAddress, timeoutMs);
socket.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
foodgetRetorfitService.getRestaurants()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
//here I'm checking the internet and server connection in the onlineTask if retrofit fail
//and if clients get Online this ( getRestaurantFromServer ) is called …Run Code Online (Sandbox Code Playgroud) 我想以十六进制格式获取视图的背景颜色。
例如,考虑int getViewBackgroundColor(View view)我的例外返回值是0Xff256e78.
我怎么能这样做?
谢谢。
我是java的新手.我只学习JPanel和JFrame.我从java软件解决方案中得到了这个说明:
"框架的包装方法根据其内容适当地设定尺寸 - 在这种情况下,框架的尺寸适合其所包含的面板的尺寸."
所以我写了这段代码:
public static void main (String [] args){
JFrame frame = new JFrame("test");
JPanel panel = new JPanel();
JLabel label1= new JLabel("");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
//frame.setSize(1000, 500);
frame.getContentPane().add(panel);
Color darkBlue = new Color(8,40,94);
panel.setSize(1000, 500);
panel.setBackground(darkBlue);
}
Run Code Online (Sandbox Code Playgroud)
但它的结果是一个非常小的窗口,我应该用鼠标最大化它来查看内容但是当我设置框架大小时,每件事情都很棒!我使用Ubuntu.那么这个问题的原因是什么?
在 Spring WebFlux 链中,我使用了有时可能返回 null 的映射操作,并且我收到警告:
Return null or something nullable from lambda in transformation mehtod。
我相信当数据为空时,它实际上不会将输入映射到,null但会引发异常。
处理这种情况的最佳方法是什么?
可为空的 Map 方法:
public Pojo parseJson(String json) {
try {
// parse
return pojo;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
我的反应链:
public Mono<Pojo> query(long id) {
Integer value = idMapper.getValue(id);
if (value != null) {
return repo.query(value)
Parse Method
|
v
.map(this::parse);
}
return null;
}
Run Code Online (Sandbox Code Playgroud) android ×3
java ×2
retrofit ×2
rx-java ×2
background ×1
colors ×1
connectivity ×1
networking ×1
reactive ×1
rx-android ×1
spring ×1
swing ×1
ubuntu ×1
view ×1