Java:erreur lors compilation

cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 28 mars 2012 à 14:04
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 29 mars 2012 à 12:55
bonjour
j'écris ce prg,lors de la compilation,ce prg me donne une erreur,
quelqu'un peut m'aider svp
import java.io.*;
public class Account 
{
 String custName; 
 String accNo;  
 String amount;
 double balance;
 public void input()
 {
     try
     {
         BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
         System.out.println("Enter the name of a account holder");
         custName=br.readLine();
         System.out.println("Enter the account number of a account holder");
         accNo=br.readLine();
         System.out.println("Enter the amount to be deposited");
         balance=Double.parseDouble(amount);
     }
     catch(Exception g)
     { 
     
     }
 }
 public void deposit()
 {
     try
     {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter the amount to be deposited");
         amount=br.readLine();
         double amt=Double.parseDouble(amount);
         balance=balance+amt;
         System.out.println("Balance: "+balance);
     }
     catch(IOException e)
     { 
     }}
 public void withdraw()
 {
     try
     {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Enter the amount to be withdraw1");
          amount=br.readLine();
          double amt=Double.parseDouble(amount);
          balance=balance-amt;
          System.out.println("balance: "+balance);
     }
     catch(IOException e)
     {
     }}
 public void display()
 {
  System.out.println("Account holder details");
   System.out.println("----------------------");
    System.out.println("Name: "+custName);
     System.out.println("Balance: "+balance);
 }}


public class Current extends Account
{
    public void chequebook()
    {
        if (balance<1000)
             System.out.println("cheque book has not been issued");
        else
         System.out.println("chèque book has been issued");
    }
    public void minimumBal()
    {
        double penalty=1000;
        if(balance<10000)
        {
            balance=balance-penalty;
        }   
    }
    public void display()
    {
     minimumBal();
     super.display();
    }
}

import java.io.*;
public class Saving1 
{
  public static void main(String a[])
{
char choice;
Saving1 obj=new Saving1();
while(true)
{
 choice = obj.menu();
 try
{
 switch(choice)
 {
 case '1':Current object=new Current();
 while(true)
 {
  System.out.println("Menu");
  System.out.println("1. Enter Details");
  System.out.println("2. Deposit Amount");
  System.out.println("3. Withdraw Amount");
  System.out.println("4. Display Balance");
  System.out.println("5. Issue ChequeBook");
  System.out.println("6. Exit");
try
{
 System.out.println("Enter your choice(1-6)");
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 char ch=(char)br.read();
 switch(ch)
 {
  case '1':object.input();
  break;
  case '2':object.deposit();
  break;
  case '3':
  object.withdraw();
  break;
  case '4':object.display();
  break;
  case '5':object.chequebook();
  break;
  case '6':choice = obj.menu();
  default:
  System.out.println("Please Enter the valid choice");
  break;
}
}
catch(IOException e)
{
}
}
case '2':
Saving object1=new Saving();
while(true)
{
  System.out.println("Menu");
  System.out.println("1. Enter Details");
  System.out.println("2. Deposit Amount");
  System.out.println("3. Withdraw Amount");
  System.out.println("4. Display Balance");
  System.out.println("5. Exit");
try
{
 System.out.println("Enter your choice(1-4)");
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 char ch=(char)br.read();
 switch(ch){case '1':
 object1.input();break;
 case '2':object1.deposit();
 break;
 case '3':object1.withdraw();
 break;
 case '4':object1.display();
 break;
 case '5':obj.menu();
 default:
 System.out.println("Please enter the valid choice");
 break;
}
}
catch(Exception e)
{
}
}
case '3'://System.out.println("Please enter the valid choice");
System.exit(0);
break;
}
 //switch
}
catch(Exception e)
{}
}
 //while
}
 //main}  

}

lors de compilations j'ai l'erreur suivante:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Saving1.menu
at Saving1.main(Saving1.java:10)
aidez moi svp

11 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
28 mars 2012 à 14:08
Bonjour,

La première chose : enlevés tous les try... catch(Exception e){}

Ça t'empêche de récupérer proprement la trace de l'erreur et donc de débugger.

Ensuite, une fois que tu auras la trace de l'erreur, donne la nous et je te dirai d'où vient le problème.
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
29 mars 2012 à 09:48
ok,j'ai corrigé mon prg,il marchais bien,
j'ai ajouté un contructor dans la class Account et l'executé ;j'ai reçu
une erreur message suivantes:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Account.
at Saving.(Saving.java:2)
at Saving.main(Saving.java:43)

import java.io.*;
public class Account 
{
 String custName; 
 String accNo;  
 String amount;
 double balance;
 
 Account(String h,String i,String j,double k)
 {
  custName=h;
  accNo=i;  
  amount=j;
  balance=k;
 }
 public void input()
 {
     try
     {
         BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
         System.out.println("Enter the name of a account holder");
         custName=br.readLine();
         System.out.println("Enter the account number of a account holder");
         accNo=br.readLine();
         System.out.println("Enter the amount to be deposited");
         balance=Double.parseDouble(amount);
     }
     catch(Exception g)
     { 
     
     }
 }
 public void deposit()
 {
     try
     {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter the amount to be deposited");
         amount=br.readLine();
         double amt=Double.parseDouble(amount);
         balance=balance+amt;
         System.out.println("Balance: "+balance);
     }
     catch(IOException e)
     { 
     }}
 public void withdraw()
 {
     try
     {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Enter the amount to be withdraw1");
          amount=br.readLine();
          double amt=Double.parseDouble(amount);
          balance=balance-amt;
          System.out.println("balance: "+balance);
     }
     catch(IOException e)
     {
     }}
 public void display()
 {
  System.out.println("Account holder details");
  System.out.println("----------------------");
  System.out.println("Name: "+custName);
  System.out.println("Balance: "+balance);
 }}

import java.io.*;
public class Current extends Account
{
    public void chequebook()
    {
        if (balance<1000)
             System.out.println("cheque book has not been issued");
        else
         System.out.println("chèque book has been issued");
    }
    public void minimumBal()
    {
        double penalty=1000;
        if(balance<10000)
        {
            balance=balance-penalty;
        }   
    }
    public void display()
    {
     minimumBal();
     super.display();
    }
}

import java.io.*;
public class Saving extends Account
{
    public void calInterest()
    {
        double interest=0;
        System.out.println(interest);
        balance=balance*Math.pow(1.05, 2);
        System.out.println(balance);
    }
        public void display()
        {
            calInterest();
             System.out.println(balance);
             super.display();
        }
        public char menu()
        {
          char choice='a';
          System.out.println("Menu");
          System.out.println("1.Current account");
          System.out.println("2.Savings account");
          System.out.println("3.exit");
          System.out.println("Enter your choice (1-3)");
        try
        {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         choice=(char)br.read();
        }
        catch(Exception e)
        {
             System.out.println("Error");
        }
        if (choice=='3')
        {
             System.exit(0);
        }
        return choice;
        }
        public static void main (String a [])
        {
            char choice;
            Saving o=new Saving();
            while(true)
            {
               // choice=o.menu();
                try
                {
                 switch(choice)
                 {
                  case '1': Current object=new Current();
                  while(true)
                  {
                   System.out.println("menu"); 
                   System.out.println("1.enter details");
                   System.out.println("2.deposit amount");
                   System.out.println("3.withdraw amount");
                   System.out.println("4.display balance");
                   System.out.println("5.issue chequeBook");
                   System.out.println("6.exit");
                try
                  {
                   System.out.println("enter your choice(1-6)");
                   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                   char ch=(char)br.read();
                   switch(ch)
                   {
                    case'1':object.input();
                    break;
                    case'2':object.deposit();
                    break;
                    case'3':object.withdraw();
                    break;
                    case'4':object.display();
                    break;
                    case'5':object.chequebook();
                    break;
                    case'6':choice=o.menu();
                    default:
                    System.out.println("Please enter the valid choice");
                    break;             
                    }
                    }
               catch(IOException e)
               {
               }                              
               }
         case'2':
               Saving object1=new Saving();
               while(true)
               {
                System.out.println("Menu");
                System.out.println("1. Enter Details");
                System.out.println("2. Deposit Amount");
                System.out.println("3. Withdraw Amount");
                System.out.println("4. Display Balance");
                System.out.println("5. Exit");
           try
           {
             System.out.println("enter your choice(1-6)");
             BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
             char ch=(char)br.read();
             switch(ch)
             {
              case'1':object1.input();
              break;
              case'2':object1.deposit();
              break;
              case'3':object1.withdraw();
              break;
              case'4':object1.display();
              break;
              case'5':o.menu();
              default:
              System.out.println("please enter the valid choice");
              break;
}}
    catch(IOException e)
    {
    }
    }
    case'3'://System.out.println("please entre the valid choice");
    System.exit(0);
    break;
    }
    //switch
    }
    catch(Exception e)
    {
    }
            }
}//while

}//main

veuillez m'aidez svp
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
29 mars 2012 à 10:00
Tu n'auras pas de réponse de ma part tant que tu n'auras pas enlevé les catch(Exception e) et que tu n'auras pas mis un e.printStackTrace() dans tous les autres blocs catch.

Sans ca, je ne peux pas savoir quelle est réellement ton erreur.
0
cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 25
29 mars 2012 à 10:24
Bonjour.
Quel IDE utilise-tu ?
Si je copie tes classes dans Eclipse, il m'indique l'erreur de compilation suivante ;
Implicit super constructor Account() is undefined for default constructor. Must define an explicit constructor


Problème qui se résoud en rajoutant un constructeur par défaut dans la classe Account.
public Account() {
 // à complèter ..  
 } 
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
29 mars 2012 à 10:26
pourquoi vous gêne le "catch exception" svp
veuillez expliquez svp
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
29 mars 2012 à 10:36
"Quel IDE utilise-tu ? "
je utilise netbeans 7.0.1
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
29 mars 2012 à 10:39
public class Account 
{
 String custName; 
 String accNo;  
 String amount;
 double balance;
 
 Account(String h,String i,String j,double k)
 {
  custName=h;
  accNo=i;  
  amount=j;
  balance=k;
 }

en ajoutant ça j'ai erreur
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: Account.
at Saving.(Saving.java:2)
at Saving.main(Saving.java:43)
0
cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 25
29 mars 2012 à 10:46
Bonjour
Va voir ce lien http://stackoverflow.com/questions/4386076/uncompilable-source-code-runtimeexception-in-netbeans
Tu as peut être un problème de cache sur tes classes compilées.

Cdt
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
29 mars 2012 à 10:51
import java.io.*;
public class Account 
{
 String custName; 
 String accNo;  
 String amount;
 double balance;
 
 Account(String h,String i,String j,double k)
 {
  custName=h;
  accNo=i;  
  amount=j;
  balance=k;
 }

maintenant j'ai erreur suivante:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - constructor Saving in class Saving cannot be applied to given types;
required: double,double
found: no arguments
reason: actual and formal argument lists differ in length
at Saving.main(Saving.java:50)
0
cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 25
29 mars 2012 à 12:01
C'est quoi la ligne 50 ?
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
29 mars 2012 à 12:55
Saving o=new Saving();
0
Rejoignez-nous