+ 4

Java: String Var in switch statements | IDE Error. Help!!!!

Java did not support using String variables in switch statements until after the release of Version 7. Even though I have JRE 8 and JDK 11, I was told that Eclipse may still be compiling, or running, my code with a default JRE or JDK that is outdated. The problem only arises when I use string variables in switch statements. I would really prefer to fix my IDE, so I can use String variables in switch statements opposed to using if/else statements. The reason being is that I am following a tutorial closely and I would rather stay on task and do it the same. I would appreciate any help. My code and the youtuber's source code is here --> https://code.sololearn.com/c0NG13LtSs87/#java UPDATE @ 9 Dec. 2018 11:52 EST For whatever reason, I could not get any of my compilers to compile and run the double switch statement. Though the problem never was solved, I have a resolution. Change the String variable, position, to an int variable and use the following chart. /* Position Variable Settings * 11 = townGate(); * 12 = talkGuard(); * 13 = attackGuard(); * 14 = crossRoad(); * 15 = north(); * 16 = east(); * 17 = west(); * 18 = fight(); * 19 = playerAttack(); * 20 = monsterAttack(); * 21 = win(); * 22 = lose(); * 23 = ending(); * 24 = defeatedMonster(); * 25 = beginNewGame(); */ ( I added a couple more of my own) The variables begin at 11 instead of 01 because I encountered yet another glitch where variables 08 and 09 are not recognized. [I like the irony how the workaround needed a workaround. lol] Proper coding habits, such as separating everything into classes, makes this glitch to never appear. In the tutorial, I am positive that the reasoning behind putting everything into one class file was to give a base understanding, of how java works, to someone who has never coded before. In his next set of tutorials he separated everything into classes properly and this glitch did not affect me. I am doing my best to document my enti

26th Nov 2018, 3:20 AM
Brandon Travis Goins
Brandon Travis Goins - avatar
8 ответов
+ 8
This sounds more like an Eclipse problem instead of the code. Have you looked around the settings to see if you can set the project target JDK to your external one instead of the embedded one? https://stackoverflow.com/questions/13635563/setting-jdk-in-eclipse/29640138
26th Nov 2018, 3:51 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
For not project specific settings: Windows > Preferences Type 'jre' in the search filter top left. Choose the jre entry > edit. Check that the path to the jdk (bin folder) is shown in the second field. Also, check that the PATH variable in the system environments is setup correctly.
26th Nov 2018, 5:44 AM
Tashi N
Tashi N - avatar
+ 3
Are you using jdk 11? I think eclipse haven't supported it yet. Not sure . Just google it EDIT: Yes I found that you have to install an extension to eclipse to fully support jdk11
26th Nov 2018, 12:24 PM
Seniru
Seniru - avatar
+ 1
Yes, it is the compiler and I have tinkered with the settings that are found in that link, but I still cannot get the settings just right, so it will work. I still need a bit more help.
26th Nov 2018, 5:16 AM
Brandon Travis Goins
Brandon Travis Goins - avatar
0
Will your tutorial allow you to use NetBeans, or any other IDE? I normally prefer eclipse, but I've had to try several IDE's in my short history in java.
28th Nov 2018, 11:30 AM
Bryan Culver
Bryan Culver - avatar
0
I have tried different versions of JDK and JRE and I still get the same issues. I do not know how to fix it.
29th Nov 2018, 9:29 PM
Brandon Travis Goins
Brandon Travis Goins - avatar
0
Answer:() : ; and:else
30th Dec 2018, 11:56 AM
Hijab Koko
Hijab Koko - avatar
0
Как тяжко не знать английский
19th Mar 2019, 12:55 AM
Life NewStudio
Life NewStudio - avatar