• 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

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

3 votes
2 answers 607 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 Gavin 15.3k points
1 vote
1 answer 9 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 Gavin 15.3k points
0 votes
2 answers 141 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 36 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 Martin K 6.6k points
0 votes
2 answers 217 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 jwilliam 3.9k points