This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!

Evert DeBoer

Ranch Hand
+ Follow
since Jun 24, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Evert DeBoer

I spent a large part of the day reading about the difference between static methods and non-static methods.

However, what I don't understand is how to exchange information between these two types of methods.

For example, if I have a static method and I want to get a value from a non-static method, I get an error message "non-static field cannot be referenced from a static context" if I call NSM.variable, where NSM is a non-static method and variable a (non-static) variable in it. The other way around is similar.

How can I get information from a non-static method using a static method?
2 years ago
OK, thanks but how do I get a value from a static method?
2 years ago
Ï have the following piece of code:



According to what I've read this should set the width of the combobox "mynumber" to 3. But I get the error "Cannot resolve symbol setPreferredSize".

What am I doing wrong?
2 years ago
Can you tell me where?
2 years ago
I have the following piece of code:



However, I get the error message that "super" should be the first statement in the construction body. But isn't it that already? (If I remove the "int", this error message disappears, but I would like the method to return a value.)

What am I doing wrong?
2 years ago

Paul Clapham wrote:
No, the JComboBox doesn't return a data type. Constructors don't return anything. However "new JComboBox(...)" creates a JComboBox object... that's what the new operator does. I don't know what kind of calculation you want to do with a JComboBox and an int, but probably that wasn't what you thought the calculation would be all about. So what exactly did you expect to be calculating?



Welll, basically I'd like to pick up the value the user has selected and then do a simple calculation with it. For example, if the user has selected "2", I'd like two load "level2".
2 years ago
Thanks, loadLevel() is a method, not a constructor., which also do not have a return type. But how can I then return a value from this constructor to the code that calls it?
2 years ago
I have two questions that regard the same piece of code. First the following:



In the first example, the call to super() should be the first statement. But isn't it already? I can get the error fixed by removing the "int" from the line above. But I would like to pass a value to the code that calls the method, and that's what the "int" is for. Can I do something smarter?




In the second example, the JComboBox returns a data type that cannot be cast to "int" (or "String" - I tried). Yet I would like to use the value in a calculation with a string or and int. How can I do this?

Thanks!
2 years ago

What do you see in IntelliJ when you click on File->Project Structure?
You should see a "Project SDK" section on the right if the "Project" option is selected on the left.
If your SDK is missing (and it sounds like it is) then click the "New" button and add it.  



Thanks! Thats works!
2 years ago
I did add the images. Sorry for posting it twice now.
2 years ago
I wanted to start to program in Java again. (I have done so before, but that was a time ago.) I use an x64 computer with Windows 10 and want to use the IntelliJ development environment.

I have installed the JDK for Windows x64 (jdk-8u121-windows-x64.exe from the site http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).

I have also added the JDK location to the SYSTEM PATH. See below.





And after that I rebooted of course.

But IntelliJ still gives me this error message once I start a new project:



Is there anyone who has got a clue what I am doing wrong? Do I have to install something extra?

Thanks!
2 years ago
Piet, do you happen to know any good Dutch Java forums? I only know the Tweakers programming forum, which is pretty good, but not Java-specific.
4 years ago