Skip to content

Commit

Permalink
Fix bug:NullPointerException when getting favicon image from a server…
Browse files Browse the repository at this point in the history
… without favicon
  • Loading branch information
RockChinQ committed Jun 22, 2021
1 parent 0f92d02 commit 838e07e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion BasicInfoAPI/src/main/conn/MinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ public String getFaviconBase64() {
@Override
public BufferedImage getFaviconImage(){
try{
return base64ToBufferedImage(getFaviconBase64().split(",")[1]);
if (getFaviconBase64()!=null)
return base64ToBufferedImage(getFaviconBase64().split(",")[1]);
}catch (Exception e){
e.printStackTrace();
}
Expand Down
12 changes: 7 additions & 5 deletions BasicInfoAPI/src/test/conn/MinecraftServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class MinecraftServerTest {
public static void main(String[] args)throws Exception {
MinecraftServer minecraftServer=new MinecraftServer("play.ee-fans.com",25565);
MinecraftServer minecraftServer=new MinecraftServer("localhost",25567);
System.out.println("available:"+minecraftServer.isAvailable());
System.out.println("version:name:"+minecraftServer.getVersionName()+" protocol:"+minecraftServer.getVersionProtocol());
System.out.println("defaultDescription:color:"+minecraftServer.getDefaultDescriptionColor()+" text:"+minecraftServer.getDefaultDescriptionText());
Expand All @@ -24,10 +24,12 @@ public static void main(String[] args)throws Exception {
}
System.out.println("favicon:"+minecraftServer.getFaviconBase64());

FaviconDisplay display=new FaviconDisplay(minecraftServer.getFaviconImage());
display.setBounds(200,200,200,200);
display.setVisible(true);
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (minecraftServer.getFaviconImage()!=null) {
FaviconDisplay display = new FaviconDisplay(minecraftServer.getFaviconImage());
display.setBounds(200, 200, 200, 200);
display.setVisible(true);
display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}
static class FaviconDisplay extends JFrame{
Expand Down

0 comments on commit 838e07e

Please sign in to comment.