Latest Questions

Get Answers to Your Coding Questions

34
Votes
Published 27 Aug, 2022
Java - How to fix tzdb.dat not found error in java?

When I try to connect my gradle project with sqlite database, I have an error: Exception in thread "main" java.lang.Error: java.io.FileNotFoundException: null\lib\tzdb.dat (The system cannot fi...

67
Votes
Published 31 Aug, 2022
Java - how to create an InputStream from a Document or Node

How can I create an InputStream object from a XML Document or Node object to be used in xstream? I need to replace the ??? with some meaningful code. Thanks. Document doc = getDocument(); InputStre...

95
Votes
Published 01 Sep, 2022
Java - Efficient data structure that checks for existence of String

I am writing a program which will add a growing number or unique strings to a data structure. Once this is done, I later need to constantly check for existence of the string in it. If I were to use...

48
Votes
Published 21 Aug, 2022
Java - Change colors of line chart Apache POI

I've generated a line chart using Apache POI. I need to change the default colors I got in the chart. Can I use RGB codes to define specific colors to each line? My code is as follows. Drawing dra...

91
Votes
Published 10 Sep, 2022
Java - CharSequence VS String in Java?

Programming in Android, most of the text values are expected in CharSequence. Why is that? What is the benefit, and what are the main impacts of using CharSequence over String? What are the main dif...

75
Votes
Published 28 Aug, 2022
Java - PowerMock and Java 8 issue: InterfaceMethodrefInfo cannot be cast to MethodrefInfo

I´m having issues while trying to execute a unit test using PowerMock with Mockito. I need PowerMockito to mock an static method. These are the versions I´m using: PowerMock 1.6.2 Mockito 1.10.19 JU...

21
Votes
Published 03 Sep, 2022
Java - Comment/uncomment a block of code in NetBeans shortcut

Is there a shortcut in NetBeans to highlight a block of code and comment/uncomment it?

46
Votes
Published 17 Sep, 2022
Java - Java Inner Classes Design Benefits

In java, you can have inner classes. I'm curious from a design perspective if there are any benefits to this. My initial thoughts are that having a separate file with the class is cleaner in separat...

47
Votes
Published 06 Sep, 2022
Java - Calling a getter in Java though reflection: What's the fastest way to repeatedly call it (performance and scalability wise)?

Given a class Foo and a property bar, neither of which I know at compile time, I need to repeatedly call the getter Foo.getBar() many, many times. Suppose I have: Method barGetterMethod = ...; // Do...

45
Votes
Published 04 Sep, 2022
Java - How to get the number of characters in a JTextField?

Is there a event on how to count the inputted character in a JTextField?

64
Votes
Published 28 Aug, 2022
Java - Invisible components still take up space JPanel

I have a series of components underneath each other in a JPanel set as a GridLayout. I need to temporarily hide the components but setVisible(false) doesn't cut it, because there is still an empty gap...

58
Votes
Published 21 Aug, 2022
Java - Java regex: check if word has non alphanumeric characters

This is my code to determine if a word contains any non-alphanumeric characters: String term = "Hello-World"; boolean found = false; Pattern p = Pattern.Compile("\\W*"); Matcher m = p.Matcher...

129
Votes
Published 01 Sep, 2022
Java - How to return JSON data from spring Controller using @ResponseBody

Spring version 4.2.0, Hibernate 4.1.4 Here is my Controller function: @RequestMapping(value = "/mobile/getcomp", method = RequestMethod.GET) @ResponseBody public List<Company> listforCompanies...

129
Votes
Published 26 Aug, 2022
Java - Using Java Advanced Imaging with Maven

The JAI setup is quite tedious, involving multiple jars and environment variables. It would aid the project's portability quite a lot if I could add it as a regular Maven dependency. The POM snippet...

93
Votes
Published 09 Sep, 2022
Java - Java "partial" override

When overriding a method in Java is it possible to call the "original" one. For example: public class A extends B{ @Override public void foo(){ System.out.println("yep"); // Then execute...

67
Votes
Published 02 Sep, 2022
Java - How to use Selenium WebDriver on local webpage (on my PC) instead of one located somewhere online?

I want to use Selenium WebDriver on a webpage that I have on my hard disc. I've tried to something like: selenium = new WebDriverBackedSelenium(driver, "C:\\...dispatcher.html"); ...instead of the...

103
Votes
Published 25 Aug, 2022
Java - Unable to configure second level cache of hibernate-ehcache-4.3.5.Final.jar in Hibernate 5.1.0.Final

I'm trying to achieve second level cache in my Java EE project using Hibernate. My Hibernate version is 5.1.0.Final. I've created a table employee in my MySQL database. I've included hibernate-ehcache...

12
Votes
Published 15 Sep, 2022
Java - "A JNI Error has occurred" for one instance of the program, not for another

I made a large program in Eclipse Java Mars on one computer which worked fine. I exported the program as a runable Jar-file and running it gave no problem whatsoever. Even when I exported the entire p...

34
Votes
Published 04 Sep, 2022
Java - how to Pass command line argument ( baseURL) using java for selenium WebDriver

i have created a runnable jar for my Selenium webDriver suite. now i have to test this in multiple base URL,As the baseURl will change according to the need. Can somebody please guide me through this....

9
Votes
Published 17 Sep, 2022
Java - making a java package in the command line

Though it's probably reccomended one uses and IDE for coding advanced java projects, I personally prefer running almost entirely command-line (using gedit as a text-editor). So please don't just tell...

73
Votes
Published 31 Aug, 2022
Java - Selenium automatically accepting alerts

Does anyone know how to disable this? Or how to get the text from alerts that have been automatically accepted? This code needs to work, driver.findElement(By.xpath("//button[text() = \"Edit\"]"))....

56
Votes
Published 31 Aug, 2022
Java - How is abstract class different from concrete class?

I understand WHY we need Abstract Class in Java - to create sub-classes. But the same can be achieved by concrete class. e.g. Class Child extends Parent. Here Parent can very well be abstract & co...

45
Votes
Published 07 Sep, 2022
Java - " java.lang.IllegalArgumentException: uri.getScheme() == null! " error using JavaFX to play audio

I'm trying to play mp3 audio on Java, and one of the forms. I belive is JavaFX, and all goes OK, until I try to play the audio. This is the code: import javax.sound.sampled.AudioPermission; import j...

210
Votes
Published 18 Sep, 2022
Java - How to get the current date and time

How do I get the current date and time in Java? I am looking for something that is equivalent to DateTime.Now from C#.

20
Votes
Published 08 Sep, 2022
Java - Can't connect to kubernetes API from inside the cluster

I'm trying to use the fabric8io/kubernetes-client in a simple example on my local minikube cluster where I get an IP of a pod import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes...

98
Votes
Published 20 Aug, 2022
Java - @SpringBootTest Error creating bean with name 'requestMappingHandlerAdapter'

I'm having problems with spring boot. I got the error Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-09-22 10:16:18.954 ERROR 13...

18
Votes
Published 13 Sep, 2022
Java - getSession().getAttribute("....") -> null

I created a signIn servlet: @WebServlet( name = "SignInServlet", description = "check email & pass", urlPatterns = {"/authorization_signin"} ) public class SignInServlet extends j...

99
Votes
Published 01 Sep, 2022
Java - slf4j logger is not printing the log in console for springboot if wrapped under log.isDebugEnabled()

I am using slf4j logger in my controller class, even though my application.properties has the following entries: #logging.level.*= DEBUG logging.level.org.springframework.web=DEBUG logging.level.com....

95
Votes
Published 06 Sep, 2022
Java - How to create a variable that can be set only once but isn't final in Java

I want a class that I can create instances of with one variable unset (the id), then initialise this variable later, and have it immutable after initialisation. Effectively, I'd like a final variable...

91
Votes
Published 08 Sep, 2022
Java - Java LocalDateTime Text could not be parsed at index 0 exception

Trying to convert a date which is in String format to Java LocalDateTime. private DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); private String caseStartDate = dateF...