[java]cannot be resolved to a type
domxaline
-
domxaline -
domxaline -
Bonjour,
program suivant en compilant s'affiche une erreur
cannot be resolved to a type
veuillez m'aidez svp
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
MyException cannot be resolved to a type
MyException cannot be resolved to a type
at Excep3.main(Excep3.java:12)
program suivant en compilant s'affiche une erreur
cannot be resolved to a type
veuillez m'aidez svp
public class Excep3
{
public static void main (String args[])
{
if(args[0]=="hello")
System.out.println("String is right");
else
try
{
throw new MyException("invalid String");
}
catch(MyException ex)
{
System.out.println(ex.getmessage());
}
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
MyException cannot be resolved to a type
MyException cannot be resolved to a type
at Excep3.main(Excep3.java:12)
3 réponses
-
j'ai corrigé ainsi
import java.lang.*; class MyException extends Exception { MyException(String message) { super(message); } } public class Excep3 { public static void main (String args[]) { if(args[0]=="hello") System.out.println("String is right"); else try { throw new MyException("invalid String"); } catch(MyException ex) { System.out.println(ex.getmessage()); } } }
maintenant j'ai erreur suivante:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method getmessage() is undefined for the type MyException
at Excep3.main(Excep3.java:24)-
-
"1. C'est crapouillaud de tout mettre au même endroit."
Je ne vois pas le problème ! Si encore ça avait été une inner classe... mais ce n'est pas le cas !
"2. Ton code est opérationnel, tu dois avoir un problème de path."
Si tu ne dis pas à domxaline qu'il faut mettre un M majuscule à getMessage, il va lui falloir 2h pour trouver !
-
-
j'ai essayé dans le cmd.exe
toujours il dit "invalid string"c:\users\pierre\java Excep3 bonjour invalid String c:\users\pierre\java Excep3 hello invalid String c:\users\pierre\java Excep3 "hello" invalid String
-