Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Switch on String in tJava

Hello,
While using the tJava component we have an error when switching on a String:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Cannot switch on a value of type String. Only convertible int values or enum constants are permitted

Talend is however configured to use a Java 7 JRE:

How is that possible ?
Kind regards,
Ivan.
Labels (3)
3 Replies
Anonymous
Not applicable
Author

Hi 
It is a compilation error, can you show us the Java code on tJava component?
Shong
Anonymous
Not applicable
Author

Hi,
Here is the code.
I can't seem to add a screenshot though. It shows on my upload list and the editor but not in the final post.
switch (input_row.TYPE) {
case "A" :
context.table = "a";
break;
case "B" :
context.table = "b";
break;
case "C" :
context.table = "b";
break;
case "D" :
context.table = "c";
break;
case "E" :
context.table = "d";
break;
default :
throw new IllegalArgumentException("Unknown truncate action !");
}

And the error message :
Starting job a at 09:53 23/01/2015.
connecting to socket on port 3837
connected
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot switch on a value of type String. Only convertible int values or enum constants are permitted
at a.b.c.tFileInputDelimited_1Process(c.java:589)
at a.b.c.runJobInTOS(c.java:914)
at a.b.c.main(c.java:757)
Job a ended at 09:53 23/01/2015.


Kind regards,
Ivan.
Anonymous
Not applicable
Author

Hi 
It is a basic Java issue, you can't use string type in switch statement expression with your JDK version, see 
http://stackoverflow.com/questions/6231907/java-7-switch-statement-with-strings-not-working
http://stackoverflow.com/questions/338206/why-cant-i-switch-on-a-string
Best regards
Shong