• Register
0 votes

Problem :

I am much more familiar with the enums in C# but it seems like enums in the Java is a quite different.

Currently I am trying to use the switch statement @ enums in my below code but I always face the below error no matter what I am doing.

The error I receive is as below:

The qualified case label MySomeClass.MyAnotherClass.MyEnum.MYVALUE_A must be replaced with the unqualified enum constant MYVALUE_A

I am able to understand the error but I am unable to write the MYVALUE_A as my enum is located in the another sub-class. Is there any way to solve my problem?

//My Main Class
public class MySomeClass {
    //My Sub-Class
    public static class MyAnotherClass {
        public enum MyEnum {
            MYVALUE_A, MYVALUE_B
        public MyEnum myEnum;
    public void mysomeMethod() { 
        MyEnum myenumExample //...
        switch (myenumExample) {
            case MyAnotherClass.MyEnum.MYVALUE_A: { <-- facing error on this line
6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The Java infers automatically any type of the elements in the case, so your labels must be unqualified as shown in below example :

int j;
switch(j) {
   case 9: // <- Here integer is expected
MyEnum mye;
switch (mye) {
   case MYVALUE_A: // <- Here an element of the enumeration is expected
9 7 4
38,600 points

Related questions

0 votes
1 answer 6 views
How I will solve this error?
asked Dec 19, 2020 TeamScript 9.5k points
0 votes
1 answer 30 views
Problem: Hello! I am a new learner. I recently started programming in C#. I learned the control statements in which I came across if, if-else, and switch statements. I tried the following program to have a better understanding of switch statement: using System; class HelloWorld ... label `case default:' I do not know what I have done wrong. Can anybody help me in figuring out what is wrong here?
asked Jan 4 Code Learner 5.5k points
0 votes
1 answer 5 views
Problem: The problem is that variables declared in one case are still visible in the subsequent cases unless an explicit { } block is used, but they will not be initialized because the initialization code belongs to another case.
asked Dec 15, 2020 Mashhoodch 5.6k points
3 votes
2 answers 1K views
Problem: Getting an error while I was working with a switch statement in c++. I do have a 200 lines code that I can&rsquo;t share with you for obvious reason. I am sharing the switch-statement block that produces the error in my program. The error I am getting is: cannot jump ... { case 1: int i = 42; dostuff(i); break; case 2: dostuff(i*2); } Any possible solution will be admitted with thanks.
asked Mar 25, 2020 Gavin 15.3k points
0 votes
1 answer 5 views
Problem Hey I Am facing an error in my calculator code. I don&rsquo;t know how to resolve this error. Will you please help me to resolve this or any other help? Here&rsquo;s my code Program: #include <iostream> #include <cmath> using namespace std;          void display_menu();  int get_menu_choice(); void ... b)   {    return (a + b);   }  int subtract(int a, int b)   {     return (a - b);   }
asked Dec 21, 2020 chris jordan 2.2k points
1 vote
1 answer 11 views
Problem: Hello Kodlogs, I am feeling good to find a helpful website like this. So many nice, and friendly people are here. Let me come to the point and put my problem here. I am new to java programming and trying to learn new things every day. I just found a new ... "Snowy"; break; case 5: dayString = "Cloudy"; break; } System.out.println(dayString); } } Please shed some light on this. Thanks.
asked Mar 26, 2020 Gavin 15.3k points
0 votes
1 answer 7 views
Problem: What is the difference between switch statement and if else statment ? can anyone explain with examples.
asked Dec 23, 2020 prog_learner 2.5k points
0 votes
2 answers 297 views
Problem : Facing following strange error the value of the for attribute of the label element must be the id of a non-hidden form control.
asked Nov 12, 2019 peterlaw 6.9k points
1 vote
1 answer 80 views
Problem: I have fundamental knowledge of Django. I have learned Django with the help of online tutorials. Recently I have started working on Django. I have recently tried to upgrade my Django to the Django 1.10. Since then I am often facing below error: TypeError: ... ), ] I have only fundamental knowledge about Django so unable to fix the above error. Kindly help me in fixing above Django error.
asked Jun 8, 2020 Martin K 6.6k points
0 votes
2 answers 333 views
Problem : After upgrading it to Django 1.10, I get below error: &ldquo;TypeError: view must be a callable or a list/tuple in the case of include().&rdquo; My urls.py is as below : from django.conf.urls import include, url urlpatterns = [     url(r'^$', 'myapp.views.home' ... r'^contact/$', 'myapp.views.contact'),     url(r'^login/$', 'django.contrib.auth.views.login'), ] How can I fix above error?
asked Jan 23, 2020 jwilliam 3.9k points