Question

I'm compiling my java project with java 4 using GNU Make which does not support generics.

Here's my little code causing the error :

 for (int i = 0; i < text.length(); i++) {
  if (text.charAt(i) > 127) {
      buffer.append("\"");
      String charValue = asciiToNascMap.get(String.valueOf((int)text.charAt(i)));
      buffer.append(String.format(";CHR$(%d);\"", charValue));
     } else {
         buffer.append(text.charAt(i));
       }
   }

   private static Map<String, String>   asciiToNascMap = new HashMap<String, String>();

static {
  asciiToNascMap.put("232", "125");//è
  asciiToNascMap.put("233", "123");//é
  asciiToNascMap.put("224", "64");//à
  asciiToNascMap.put("231", "92");//ç
  asciiToNascMap.put("199", "180");//Ç
  asciiToNascMap.put("234", "193");//ê
}

I'm getting this error :

 Printer.java:319: error:Cannot find method "java/lang/String.format(java.lang.String, java.lang.String)"

Here's the signature of the String.format method :

 /**
 * Returns a formatted string using the specified format string and
 * arguments.
 *
 * <p> The locale always used is the one returned by {@link
 * java.util.Locale#getDefault() Locale.getDefault()}.
 *
 * @param  format
 *         A <a href="../util/Formatter.html#syntax">format string</a>
 *
 * @param  args
 *         Arguments referenced by the format specifiers in the format
 *         string.  If there are more arguments than format specifiers, the
 *         extra arguments are ignored.  The number of arguments is
 *         variable and may be zero.  The maximum number of arguments is
 *         limited by the maximum dimension of a Java array as defined by
 *         <cite>The Java&trade; Virtual Machine Specification</cite>.
 *         The behaviour on a
 *         <tt>null</tt> argument depends on the <a
 *         href="../util/Formatter.html#syntax">conversion</a>.
 *
 * @throws  IllegalFormatException
 *          If a format string contains an illegal syntax, a format
 *          specifier that is incompatible with the given arguments,
 *          insufficient arguments given the format string, or other
 *          illegal conditions.  For specification of all possible
 *          formatting errors, see the <a
 *          href="../util/Formatter.html#detail">Details</a> section of the
 *          formatter class specification.
 *
 * @throws  NullPointerException
 *          If the <tt>format</tt> is <tt>null</tt>
 *
 * @return  A formatted string
 *
 * @see  java.util.Formatter
 * @since  1.5
 */
public static String format(String format, Object ... args) {
    return new Formatter().format(format, args).toString();
}
Was it helpful?

Solution 2

You cannot use String.format in Java 1.4.

Try:

buffer.append(";CHR$(").append(Integer.valueOf(charValue)).append(");\"");

OTHER TIPS

The method you are trying to use is not available in Java 1.4. See the @since tag in your posted commentary. It says @since 1.5 meaning it was intoduced in Java 1.5.

String.format is not available in Java 1.4. This is indicated in the text you posted in the @since tag. varargs support was not added until Java 5, which is why it probably wasn't added until then. People have created C printf-style libraries, however.

See these links:

http://www.sharkysoft.com/archive/printf/docs/javadocs/lava/clib/stdio/doc-files/introduction.htm http://www.cs.ubc.ca/~lloyd/java/doc/cformat.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top