• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Using calendar class with Arraylist

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Im trying to display a train time table to look like this
Station      Arrival     Departure Day
Vancouver                   20:30 1
Kamloops         06:00   06:35 2
Jasper        16:00   17:30 2
Edmonton        23:00   23:59 2
Saskatoon        08:00   08:25 3
Winnipeg        20:45    22:30 3
Sioux Lookout 05:02   05:42 4
Hornepayne 15:35   16:10 4
Capreol        00:18    00:48 5
Toronto        09:30        5

This is my code



and



The result is get in command prompt is



How can I get rid of the null and put in the appropriate times and days?
Thank you in advance for any help.
 
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Java 8, which I would highly recommend, use the LocalTime class not the Calendar class.


I'm not sure why you're doing this when you have a Station#toString() method defined (though it could use some tweaks).

This would be much cleaner.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Thank you for the help. I tried doing what you said



but I am getting these erros




I must be missing something, please help.
 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package java.time does not exist

This means you are using an older version of Java. Can you update your Java to version 8 ?
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I installed it and still getting the error


 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you get with
javac -version
?
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javac 1.7.0_80
 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing you installed Java not the Java Development Kit (JDK). You'll need the Java 8 JDK in order to compile correctly.
 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i downloaded the current version but javac -version is still coming up 1.7...
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do your PATH and JAVA_HOME environment variables look like?

Windows:
C:>path

and

c:> echo %JAVA_HOME%

Linux:
$ echo $PATH

and

$ echo JAVA_HOME
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\Administrator>path
PATH=C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_80\bin;;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps

C:\Users\Administrator>echo %JAVA_HOME%
%JAVA_HOME%
 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Gordon wrote:C:\Users\Administrator>path
PATH=C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_80\bin;;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps

C:\Users\Administrator>echo %JAVA_HOME%
%JAVA_HOME%


Your path should replace the bolded section with
%JAVA_HOME%\bin

And you should create a brand new environment variable
JAVA_HOME
set to
C:\Program Files\Java\jdk1.8.0_151
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried that it didn't work.
 
Marshal
Posts: 80093
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Gordon wrote:. . . . . . .

Whenever you get your installation problem sorted out, use the java.time classes instead of Calendar, not in addition to. More details of the newer classes here in the Java™ Tutorials.

Always tell us what is going wrong, not “it doesn't work”. Start with the results of passing
echo %PATH%
or simply path
to the command line. Make sure to follow Carey't instructions. You have to be exact to the letter.
 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Gordon wrote:I tried that it didn't work.


Ok, you've changed the path and JAVA_HOME, just to double check re-run

C:>path

and

c:> echo %JAVA_HOME%

And post the results
 
Carey Brown
Bartender
Posts: 10964
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:C:\Program Files\Java\jdk1.8.0_151


Also, use Windows Explorer to verify that this directory exists.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did as you said and made my system variables as follows

PATH=C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;  %JAVA_HOME%\bin;;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
and

The JAVA_HOME to C:\Program Files\Java\jdk1.8.0_151

still not working please help.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:

c:>where javac

and post what gets printed
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\Administrator>where javac
'where' is not recognized as an internal or external command,
operable program or batch file.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never seen a Windows OS that didn't have "where.exe".  Hmm...

Okay, the "wrong" javac is probably in here:

C:\ProgramData\Oracle\Java\javapath

Not sure what to do without messing with your PATH variable.  Get me a second...
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One last thing before we change your PATH.  Type this:

C:\>dir C:\ProgramData\Oracle\Java\javapath

...and post what it displays.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\Administrator>C:\>dir C:\ProgramData\Oracle\Java\javapath
'C:\' is not recognized as an internal or external command,
operable program or batch file.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah!  At the command prompt, just type this:

where javac

...and press return.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\>where javac
'where' is not recognized as an internal or external command,
operable program or batch file.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Drat!  Okay, just this at the command prompt:

dir C:\ProgramData\Oracle\Java\javapath

Press <enter> and post the result.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\Administrator>dir C:\ProgramData\Oracle\Java\javapath
Volume in drive C has no label.
Volume Serial Number is 86EE-9CE9

Directory of C:\ProgramData\Oracle\Java\javapath

12/18/2017  05:37 PM    <DIR>          .
12/18/2017  05:37 PM    <DIR>          ..
12/18/2017  05:36 PM           206,912 java.exe
12/18/2017  05:36 PM           206,912 javaw.exe
12/18/2017  05:36 PM           319,552 javaws.exe
              3 File(s)        733,376 bytes
              2 Dir(s)  394,987,880,448 bytes free
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is javac.exe hiding?  Okay, try this:

dir C:\WINDOWS\system32\java*.*

and post the results.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\Administrator>dir C:\WINDOWS\system32\java*.*
Volume in drive C has no label.
Volume Serial Number is 86EE-9CE9

Directory of C:\WINDOWS\system32

01/10/2017  08:56 PM    <DIR>          java
09/29/2017  08:41 AM            94,720 JavaScriptCollectionAgent.dll
06/29/2017  03:22 PM           318,528 javaws.exe
              2 File(s)        413,248 bytes
              1 Dir(s)  393,966,690,304 bytes free
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you changed the PATH or JAVA_HOME, did you start a new command window?  If not, exit the command window and restart it.  Then type

javac -version

and see if it's Java 8.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\Administrator>javac -version
'javac' is not recognized as an internal or external command,
operable program or batch file.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the Windows Explorer and see if you can find this folder:

C:\Program Files\Java\jdk1.8.0_151\bin

Does it have javac.exe in it?
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this file C:\Program Files (x86)\Java\jdk1.8.0_151\bin i have javac
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it doesnt end with .exe though
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, change JAVA_HOME to:

C:\Program Files (x86)\Java\jdk1.8.0_151

Then you should be ok.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually already have it set to that I cant believe this happened all I tried to do was get the newest java version:(
Thank you for all your help so far i appreciate it.
 
Campbell Ritchie
Marshal
Posts: 80093
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Gordon wrote:it doesnt end with .exe though

Maybe your Windows® Explorer has the hide extensions for well-known file types option turned on.

What happens when you pass path or echo %PATH% to a command line? Are you still getting the same response from java -version and javac -version? Have you got either C:\Program Files (x86)\Java\jdk1.8.0_151\bin or %JAVA_HOME%\bin in your PATH? Did you install Java® into the x86 folders, or did it do that by itself? Please confirm whether you downloaded a 32‑bit version or a 64‑bit version of the JDK. Have you still got the space in the PATH before %JAVA_HOME%?

Short of getting remote access to your computer (we promise to copy all your card numbers and empty your bank accounts), we can only help if we get the full details from you.
 
Ryan Gordon
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe your Windows® Explorer has the hide extensions for well-known file types option turned on.

What happens when you pass path or echo %PATH% to a command line? Are you still getting the same response from java -version and javac -version? Have you got either C:\Program Files (x86)\Java\jdk1.8.0_151\bin or %JAVA_HOME%\bin in your PATH? Did you install Java® into the x86 folders, or did it do that by itself? Please confirm whether you downloaded a 32‑bit version or a 64‑bit version of the JDK. Have you still got the space in the PATH before %JAVA_HOME%?

Short of getting remote access to your computer (we promise to copy all your card numbers and empty your bank accounts), we can only help if we get the full details from you.



C:\Users\Administrator>path
PATH=C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.8.0_151 \bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;

C:\Users\Administrator>echo %PATH%
C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.8.0_151 \bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;

I put it in that folder by myself and I downloaded a 64 bit version as my computer is 64 bit. Lol that was a joke about the bank accounts right :P
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's the problem!  You have an extra space in your PATH.

Check your JAVA_HOME variable; edit it and go to the end of the text.  There will probably be a space at the end.  Delete it.

Now, remember to exit and restart a command window, then type:

javac -version
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the "quote" button for that post it looks like it's actually a new line, and not a space.
 
Good night. Drive safely. Here's a tiny ad for the road:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic