Please Help

I got four compiler error messages.

I am not sure how to fix them.

String.java:9: incompatible types

found: java.lang.String

required: String

String greeting = "hello";

^

String.java:10: cannot resolve symbol

symbol : method length ()

location: class String

int len = greeting.length();

^

String.java:11: cannot resolve symbol

symbol : method charAt (int)

location: class String

char ch = greeting.charAt(1);

^

String.java:12: cannot resolve symbol

symbol : method substring (int,int)

location: class String

String sub = greeting.substring(2,4);

^

4 errors

// my code is below:

import java.io.*;

import java.lang.*;

public class String

{

public static void main (String [] args)

{

File file = new File("c:\\java\\string.txt");

String greeting = "hello";

int len = greeting.length();

char ch = greeting.charAt(1);

String sub = greeting.substring(2,4);

try

{

PrintWriter writer = new PrintWriter(new FileWriter(file));

writer.println("String greeting = " + greeting);

writer.println("int len = greeting.length() = " + len);

writer.println("char ch = greeting.charAt(1) = " + ch );

writer.println("String sub = greeting.substring(2,4) = " + sub);

System.out.println("String greeting = " + greeting);

System.out.println("int len = greeting.length() = " + len);

System.out.println("char ch = greeting.charAt(1) = " + ch );

System.out.println("String sub = greeting.substring(2,4) = " + sub);

writer.close();

}

catch(Exception e)

{ System.out.println( e ); }

}

}

[1781 byte] By [etow1288a] at [2007-9-30 0:55:41]
# 1
Stop trying to define class String. Java already has a class with that name.
bschauwejavaa at 2007-7-16 5:28:46 > top of Java-index,Java Essentials,New To Java...
# 2

You have declared your class as String with the statementpublic class String

So now, when you use String to type a field, you must tell Java which one you mean. In your case, you need to use the fully quilified name of the String class that comes with java. So, change all of your String vars to java.lang.String

or name your class something else.

mgumbsa at 2007-7-16 5:28:46 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks for your help.
etow1288a at 2007-7-16 5:28:46 > top of Java-index,Java Essentials,New To Java...
# 4
thanks
fresh221a at 2007-7-16 5:28:46 > top of Java-index,Java Essentials,New To Java...