Liutauras Vilda

Marshal
+ Follow
since Nov 12, 2014
Liutauras likes ...
BSD
software developer, moderator at coderanch, a father, husband and nintendo switch owner
London, United Kingdom
Cows and Likes
Cows
Total received
364
In last 30 days
7
Total given
1049
Likes
Total received
1098
Received in last 30 days
13
Total given
1010
Given in last 30 days
11
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Liutauras Vilda

Your most recently posted stack trace and most recently posted code are still out of sync.
Stack trace indicates, that error goes through line 26, which is empty in your posted code.

Not sure what are the reasons you are not showing us the correct ones.
8 hours ago
Error message is from different class (Oracle_select3) than you show us. Please show that class.
11 hours ago
I think you are at the stage when you really need to pick up testing framework (JUnit not a bad option) and start testing each of your classes along with each of their methods.

Now you have a bunch of lines of code, and you don't know where the things start falling apart. That leads to desperate decisions and chaos in a code. I've experienced that many times already. To cut corners and write production code ("to speed up things") proves to be a bad decision almost always.
1 day ago

So you have this code which trying to set Major, which is initially null at line 4 (in my snippet). Now you are trying to obtain the major from the Catalog based on major's name. So in case name is found within the catalog you assign it to major.

But in case it is not found within the catalog, what's then? major is left with null value.

Is clear?
1 day ago
So t is null. Which is the result after calling getMajor() I guess. Carey already mentioned correctly where the root problems most likely start.
1 day ago
So what is at line 91 in StudentInfo?!?
1 day ago
Split that offending line (shown in stack-trace as line 86 I think) to several lines, you'll know exactly what is null.

i.e.
majorName.setText(s.getMajor().getName());

to:
Type t = s.getMajor();
Type t1 = t.getName();

majorName.setText(...);

1 day ago
Welcome to the Ranch.

You said you stuck, but you didn't explain what stopped you.

One more thing. When you post code, don't forget to use code tags. Simply select the code snippet and hit the Code button in the text assembling panel.

An example how code would look like using code tags:

And compare with the version without the code tags, basically as you have:

public class Test {

    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

As you see former version is much better to read, understand and discuss (as it has line numbers and adds some colour coding).
1 day ago
For an interest, let's have a look what most recent IntelliJ IDEA (build 181.3741.2) give as a warn for having such code:

The value changed at 'i++' is never used.
This inspection points out the cases where a variable value is never used after its assignment, i.e.:  - the variable never gets read after assignment OR  - the value is always overwritten with another assignment before the next variable read OR  - the variable initializer is redundant (for one of the above two reasons)

1 day ago

Dave Tolls wrote:The post-increment operator returns the value before the increment.

So i is 0 initially, i++ will return 0, so i = i++ will reset i back to zero after the increment.




Of course it is correct, but I think this question is most difficult one to explain in some comprehensive way so the starter would understand easily.

@OP in case you didn't get what Dave explained, here, in addition to Dave's explanation, is mine one.

When you have an expression like this:
i = i++;

Post increment means, you place current i value to an expression and only then increment.

So, since i is equal to 0 at the beginning, what you get is:
i = 0;

then at some moment in time, as an intermediate step, i get's incremented to 1 for a blink of an eye, but it gets discarded (not sure I can use this wording), because the actual assignment takes place which makes i to be assigned to 0 as shown above. And the story from here repeats over and over (because you have loop).

1 day ago

ras oscar wrote:See post 14 in this thread. The only thing I have changed is to remove all the import statements from the top of the 2 files. The compiler runs without complaint and emits the 2 expected classes. The run program ( runner?) complains it can't find the data class. All files are located in the same directory, both .java and .class (And .bat, if it matters). The files are all located in c:\Java\Command Line\Data


Then...

For compiling:
javac *.java

For executing:
java DataMain

Verified locally, works
1 day ago

ras oscar wrote:is there a java system design reason why the compiler will look in the current directory but the run  application won't? I assume the "application deployment"  solution would be to combine all the required classes into a .jar file and run that. No?


Not sure I follow. Can you post [1] exact classes you have, [2] where they are,  and [3] in which directory you are when we talking. Then I'll write you how to compile and how to execute code.
Somehow lately I think that you confusing what the packages are and what the present working directory is, and perhaps what the classpath is.

Good that you trying to understand it though, it is really worthwhile time investment.
1 day ago

Tim Holloway wrote:Or, if you prefer: "java -classpath=. Data" which you can abbreviate to simply "-cp".


Tim, I don't think it would go through.

In particular first one. I think (almost certain) it needs to be:
java -classpath . something

Meaning, without the = (equals) sign. Quotes aren't needed too, but I think you added these just to emphasize expression boundaries.

However, while I know -cp behaves same (read on various books) as -classpath, I don't know what is the actual story about them? Never found comprehensive explanation. Might be because "nearly half of a century back, there were created C, and..."?
2 days ago
@OP
Maybe having structure similar to this would help to you decompose task to smaller tasks?

example:
2 days ago