Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:19+00:00 2026-06-17T09:26:19+00:00

I was practicing the other day and I came accross this error with a

  • 0

I was practicing the other day and I came accross this error with a string for a switch:

Cannot switch on a value of type String. Only int values or enum constants are permitted

I’m not sure how I would fix this so I came here for help. I am using Eclipse. Here is the source, the second VARIABLE (in caps) is where I get the error:

public class Switch {
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.println("Please enter a command: ");
    String VARIABLE = input.nextLine();

    switch (VARIABLE) {
    case "start":
        System.out.println("Machine started!");
        break;

    case "stop":
        System.out.println("Machine stopped!");
        break;

    default:
        System.out.println("Invalid command");
    }

}
}

It’d be cool if someone can help me with this. I’m relatively new to this so I’m not sure if any of this even makes sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:26:20+00:00Added an answer on June 17, 2026 at 9:26 am
    switch (VARIABLE) {
    

    switch with Strings are supported from Java 7 onwards. I guess you are using lower version of java you need to either upgrade your java version to 7 (or) remove String from switch and use supported types.

    Here is oracle tutorial on switch statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Started practicing with XML and C# and I have an error message of There
I am practicing at getting consistent with my error handling, and I keep hoping
I am practicing this https://developer.mozilla.org/en/Canvas_tutorial/Basic_animations Clock tutorial. Everything in the code is clear to
practicing programming with MyProgrammingLab and getting following compile error: ApartmentBuilding.java:4: error: expected its also
while practicing recursive functions, I have written this code for fibonacci series and (factorial)
I'm practicing with the Key Value Observing, but it's something I do not quite
I am practicing sending emails with Google App Engine with Python. This code checks
While practicing for certification, I came across one MCQ the question. It was as
I'm practicing using mulitple files and header files etc. So I have this project
I'm practising on threading and came across this problem. The situation is like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.