Skip to content

Tag: java

Initializing variable in try catch block

I am getting the error in Java: Exception in thread “main” java.lang.Error: Unresolved compilation problem The local variable b1 may not have been initialized at Test.main(Test.java:20) Here is my code: Answer The problem here is that getBytes(String encoding) throws UnsupportedEncodingException. …

Jackson Serialize Field to Different Name

I have this JSON to deserialize: I want to serialize it to 2 different formats: [A] [B] I’m able to serialize it to 1 format: [A] only or [B] only. Here’s my code to serialize it to [B]: I read about JsonView here http://www.baeldung.com/jackson-json-view-annotation (section ‘5. Customize JS…

LinkedList remove at index java

I’ve made a remove method from scratch that removes a Node from a linked list at a specified index. It’s not removing the correct Node. I’ve tried to step through with the debugger in eclipse but couldn’t catch the problem. Each Node contains a token. I have included the Token class, N…

How to detect EOF in Java?

I’ve tried some ways to detect EOF in my code, but it still not working. I’ve tried using BufferedReader, Scanner, and using char u001a to flag the EOF, but still not make any sense to my code. Here is my last code : The program supposed to stopped when it’s already reached the EOF, but I do…