[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)
A voir également:
- String cannot be resolved to a type
- Qwerty to azerty - Guide
- Clear type - Guide
- Wfp to mp4 - Forum Accessoires & objets connectés
- Mb to mo ✓ - Forum Matériel & Système
- Iptv sorry this video cannot be played - Forum Téléviseurs
3 réponses
j'ai corrigé ainsi
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)
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)
Ah, les exceptions, on peut en écrire des bouquins.
1. C'est crapouillaud de tout mettre au même endroit. Créée une classe MyException à part.
2. Ton code est opérationnel, tu dois avoir un problème de path. Chez moi, ca compile et ça s'execute.
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 !