Olá pessoal, estou com o seguinte erro:
Código:
class ReverseString {
public static String reverseIt(String inicial) {
int i, tam = inicial.length();
StringBuffer dest = new StringBuffer(tam);
for (i = (tam - 1); i >= 0; i--) {
dest.append(inicial.charAt(i));
}
return dest.toString();
}
}
Erro:
--------------------Configuration: j2sdk1.4.2 <Default>--------------------
D:\Estudo\Exercicios\TesteStringBuffer.java:21: cannot access StringBuffer
bad class file: D:\Estudo\Exercicios\StringBuffer.java
file does not contain class StringBuffer
Please remove or make sure it appears in the correct subdirectory of the classpath.
StringBuffer resultado;
^
1 error
Será que pode ser a versão do j2sdk…???
Obrigado pela atenção,
Marcos
[size=“11”][color=“red”]* Editado: Lembre-se de utilizar BBCode em seus códigos - Matheus [/color][/size] :joia:
A versão do jdk está certa. O que acontece é que no diretório você tem um arquivo chamado StringBuffer.java e ele tenta procurar a classe nesse arquivo. Existem 2 maneiras de resolver isto:
1ª (Pior):
Renomear esse arquivo de StringBuffer.java para outra coisa
2ª (Acho esta melhor):
No seu arquivo TesteStringBuffer.java coloca na primeira linha:
import java.lang.StringBuffer;
Espero ter ajudado…
Flw…
Sempre lembrando:
Tentem nunca nomear suas classes com nomes que coincidam com classes do pacote java.lang. Isso dá uma confusão danada que não é fácil de resolver.
É melhor ter uma classe chamada “TesteStringBuffer” ou “ExercicioStringBuffer” que uma classe chamada “StringBuffer”.
Como são poucas classes, dá para viver com essa restrição. Dica: se o nome de sua classe for em português, provavelmente nunca terá problemas.
AbstractMethodError
Appendable
ArithmeticException
ArrayIndexOutOfBoundsException
ArrayStoreException
AssertionError
Boolean
Byte
CharSequence
Character
Character.Subset
Character.UnicodeBlock
Class
ClassCastException
ClassCircularityError
ClassFormatError
ClassLoader
ClassNotFoundException
CloneNotSupportedException
Cloneable
Comparable
Compiler
Deprecated
Double
Enum
EnumConstantNotPresentException
Error
Exception
ExceptionInInitializerError
Float
IllegalAccessError
IllegalAccessException
IllegalArgumentException
IllegalMonitorStateException
IllegalStateException
IllegalThreadStateException
IncompatibleClassChangeError
IndexOutOfBoundsException
InheritableThreadLocal
InstantiationError
InstantiationException
Integer
InternalError
InterruptedException
Iterable
LinkageError
Long
Math
NegativeArraySizeException
NoClassDefFoundError
NoSuchFieldError
NoSuchFieldException
NoSuchMethodError
NoSuchMethodException
NullPointerException
Number
NumberFormatException
Object
OutOfMemoryError
Override
Package
Process
ProcessBuilder
Readable
Runnable
Runtime
RuntimeException
RuntimePermission
SecurityException
SecurityManager
Short
StackOverflowError
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
StringIndexOutOfBoundsException
SuppressWarnings
System
Thread
Thread.State
Thread.UncaughtExceptionHandler
ThreadDeath
ThreadGroup
ThreadLocal
Throwable
TypeNotPresentException
UnknownError
UnsatisfiedLinkError
UnsupportedClassVersionError
UnsupportedOperationException
VerifyError
VirtualMachineError
Void
Obrigado pessoal, vou estar seguindo essas dicas…
marcos