今天我得到了一个NullPointerException,它实际上不会发生.
Exception in thread "Timer-9" java.lang.NullPointerException
at packagename.censored.Bot.changeServergroups(Bot.java:1363)
at packagename.censored.Bot.xpTask(Bot.java:1239)
at packagename.censored.Bot.access$7(Bot.java:1187)
at packagename.censored.Bot$9.run(Bot.java:729)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Run Code Online (Sandbox Code Playgroud)
这是代码的相关部分:
public void changeServergroups(int cldbid, ArrayList<Integer> addList, ArrayList<Integer> removeList) {
// If there are groups to add AND delete, remove them from the lists
if (addList != null && removeList != null) {
ArrayList<Integer> temp = new ArrayList<Integer>(addList);
for (int s : temp) { // THIS IS LINE 1363
if (removeList.contains(s)) {
addList.remove((Integer) s);
removeList.remove((Integer) s);
}
}
}
// some more …Run Code Online (Sandbox Code Playgroud) 我有一个大小为 32x32px 的各种图标的 CSS 精灵。
现在我需要以 20x20px 大小显示这些图标之一。我尝试了一些方法,例如将大小设置为 20px、使用 background-size:cover 或使用 transform:scale(0.625) - 但我的尝试都没有给出我想要的结果。
我的测试的 HTML:
32px icons:
<div class="sprite" style="background-position:0px 32px;"> </div>
<div class="sprite" style="background-position:64px 32px;"> </div>
<div class="sprite" style="background-position:32px 96px;"> </div>
<div class="sprite" style="background-position:0px 0px;"> </div>
<div class="sprite" style="background-position:32px 64px;"> </div>
<hr>
20px icons (attempts):
<div class="sprite" style="background-position:32px 64px; width:20px; height:20px;"> </div>
<div class="sprite" style="background-position:32px 64px; width:20px; height:20px; background-size:cover;"> </div>
<div class="sprite" style="background-position:32px 64px; width:20px; height:20px; transform:scale(0.625);"> </div>
Run Code Online (Sandbox Code Playgroud)
我的测试的 CSS:
.sprite {
background-image:url(http://buildnewgames.com/assets/article//dom-sprites/spritesheet.png);
width:32px;
height:32px;
}
Run Code Online (Sandbox Code Playgroud)
请看一下这个小提琴,看看我尝试了什么:
我想将原始长数组转换long[] l1 = { 1, 2, 3, 4 };为String.此String应具有这些值中的每一个,以,as分隔符分隔.
我想通过使用Java 8的流来实现这一点.我已经将它用于Long[]数组,但由于某种原因,我不能让它为原语工作long[].
public static void main(String[] args) {
long[] l1 = { 1, 2, 3, 4 };
Long[] l2 = new Long[4];
l2[0] = new Long(1);
l2[1] = new Long(2);
l2[2] = new Long(3);
l2[3] = new Long(4);
System.out.println(longToString(l2));
}
public static String longToString(Long... l) {
String[] x = Arrays.stream(l).map(String::valueOf).toArray(String[]::new);
String y = Arrays.stream(x).collect(Collectors.joining(","));
return y;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使这项工作longToString(long... l)取而代之longToString(Long... l) …