Here is my code (it is code to reverse a given string) But I cannot take in input because when I try to take the string input I get a “cannot find symbol error” even though I have clearly defined the variable “text”. This question is from MOOC.fi’s Java OOP course, and can be fou…
Tag: compiler-errors
Two java files. Getting IllegalAccessError when running class with main method trying to access a method from the other file
Learning Java. I have two files, each containing one java class. When I run the file with the main method, I get the following error: Exception in thread “main” java.lang.IllegalAccessError: failed to access class TapeDeck from class TapeDeckTestDrive (TapeDeck is in unnamed module of loader ̵…
JAVA ERROR : package com.sun.rowset is not visible : com.sun.rowset is declared in module java.sql.rowset, which does not export it
I’m simply try to run this code: When I run it I get: Error:(1, 15) java: package com.sun.rowset is not visible (package com.sun.rowset is declared in module java.sql.rowset, which does not export it) I’m using IntelliJ and I tried to import rs2xml.jar, and that still doesnt help. Answer As of Jav…
IntelliJ IDEA cannot resolve static import
When I import regularly it works as expected: However, if I change an import to static, IDEA cannot resolve it: Gradle builds the project successfully. It seems to be a problem with IDEA but I can’t find if it is a known problem. I tried cleaning, invalidate caches etc. Anything else I can do? Im using …
Java how to return an array with fibonacci values starting at 1?
I’m writing a void function fibFill which fills an array with Fibonacci numbers. It doesn’t have to return anything. Here’s what I have so far: For example, if I pass an array of length 5 to the method, it will override the contents of the passed array like this: [1, 1, 2, 3, 5] Answer Your …
Java cooperating generic classes: can we avoid unchecked cast?
I have two abstract generic classes. They cooperate and hence depend on each other. Occasionally one needs to pass this to the other. I am trying to find a type safe way to do this: My question is whether I can find a cleaner way so I avoid the unchecked cast in AbstractB.setA(). I had hoped to declare it set…
ObjectInputStream readObject in while Loop
Is it possible to read from ObjectInputStream in while loop which will terminate by exception thrown by socket timeout socket.setSoTimeout(4000); Answer When you say ‘not working’, what you really mean is ‘not compiling’, for reasons that are stated in the compiler message: Object isn&…
Java: “Local variable may not have been initialized” not intelligent enough?
Consider the following method: On x++ I get the “Local variable may not have been initialized” error. Clearly x will never be used uninitialized. Is there any way to suppress the warning except by initializing x? Thanks. Answer No, there is no way Java can examine all possible code paths for a pro…
Why do I get “must override a superclass method” with @Override?
The following code generates this error message at the public void onClick line. Multiple markers at this line – implements android.view.View.OnClickListener.onClick – The method onClick(View) of type new View.OnClickListener(){} must override a superclass method I can’t understand why. This…
Cannot make a static reference to the non-static method
Building a multi-language application in Java. Getting an error when inserting String value from R.string resource XML file: This is the error message: Error: Cannot make a static reference to the non-static method getText(int) from the type Context How is this caused and how can I solve it? Answer Since getT…