aspose file tools*
The moose likes Java in General and the fly likes what is the problem with my java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "what is the problem with my java code" Watch "what is the problem with my java code" New topic
Author

what is the problem with my java code

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

error is



The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Alexander Kober
Ranch Hand

Joined: Aug 05, 2011
Posts: 32

As you can see in line 10, the constructor of class 'Playing' takes a String argument. The field Playing#name is of type Playing.Name, an enum you defined. Java will not automatically convert a String to the corresponding enum value. In line 40, you actually do pass an enum to the constructor, so i guess all you'll want to do is replace line 10 with

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Also, the setNames method seems wrong. First of all, it doesn't set anything, so it should be called getName instead. Second, it can be implemented so much easier:
And should you ever need to convert a String into one of your enum constants, you can use Name.valueOf("thriller").


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Alexander Kober wrote:As you can see in line 10, the constructor of class 'Playing' takes a String argument. The field Playing#name is of type Playing.Name, an enum you defined. Java will not automatically convert a String to the corresponding enum value. In line 40, you actually do pass an enum to the constructor, so i guess all you'll want to do is replace line 10 with


thanks for guiding me . my doubt is clear now but i want to ask 1 question which is
when i change to this so after changing this i thought it should not produce an error but it did , i m passing an String value which is accepted by constructor Playing(String name) then it should set the name to the value of constructor then i m calling the which should set the appropriate name according to the value of name variable into names variable
the error is
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Well, you can't use Strings inside switch statements. (Well, since Java 7 you can, but you'd need to compare them to String values.)
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Rob Spoor wrote:Well, you can't use Strings inside switch statements. (Well, since Java 7 you can, but you'd need to compare them to String values.)

thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the problem with my java code