Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Using your New Tools Multiple Strings

ADAM GROCHOWSKI
ADAM GROCHOWSKI
158 Points

How to resolve an unknownFormatConversionException?

How do I resolve the UnknownFormatConversionException? This is a beginner level video and I already cannot get it to work. Grrr!

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'i'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)
at java.util.Formatter.parse(Formatter.java:2560)
at java.util.Formatter.format(Formatter.java:2501)
at java.util.Formatter.format(Formatter.java:2455)
at java.io.Console.format(Console.java:170)
at java.io.Console.printf(Console.java:209)
at TreeStory.main(TreeStory.java:15)

3 Answers

Simon Coates
Simon Coates
8,377 Points

It's typically difficult to debug code absent the source code. You can post your source code in various ways (sharing a workspace 'snapshot' link or using a markdown syntax to correctly format code). However, you've probably got an incorrect placeholder string (or maybe haven't saved since you made a mod). With the following code, I used %w as an example of an incorrect placeholder and then used the %s as a correct example.

import java.io.Console;

public class TreeStory {

    public static void main(String[] args) {
        Console console = System.console();
        /*  Some terms:
            noun - Person, place or thing
            verb - An action
            adjective - A description used to modify or describe a noun
            Enter your amazing code here!
        */
        String name  = console.readLine("Enter a name:");
        String adjective = console.readLine("Enter an adjective:");
        try {
          console.printf("%w is %s.", name, adjective); //throws an unknownFormatConversionException
        } catch (Exception e){
          console.printf(""+e.getClass());
        }
        console.printf("%s is %s.", name, adjective);
    }
}

Try/catch are just in the above so I can throw the error and then still demo the functioning code. With Java exceptions, you can typically just google them and look at the line number in the stacktrace to see where the problem is. Your stacktrace placed the error at line 15 in your code ("at TreeStory.main(TreeStory.java:15)").

The next video has some introductory content on debugging. I think they present compile time errors to start with. These are errors that prevent compilation. A runtime error is something where the program is able to compile and run, but crashes during execution. So it might look a little different to the errors he demos.

ADAM GROCHOWSKI
ADAM GROCHOWSKI
158 Points

Well I must say thank you! I did not know what Markdown meant but now reviewing the hyperlink, I see your point and more on how to create a snapshot of my code.

Also, I cannot say for certain but I commented out the problematic line and then took away the forward slashes, resaved it, recompiled it, and it now works! Thank you for taking the time to reply.

Simon Coates
Simon Coates
8,377 Points

In your code, you seemed to have % rather than %s. You could get a similar result if you had modified the string to the correct one, but hadn't saved (and recompiled). As for my comment about markdown, there's an explanation at https://teamtreehouse.com/community/posting-code-to-the-forum . A snapshot is probably more helpful in that a user can clone your workspace and test it directly.