2016-11-08 86 views
-4

我不知道我的代碼在哪裏投擲它的流。它有我不知道他們如何工作的各種錯誤。通過類異常的控制流不支持super(int)的超級參數,就像super(string)類型一樣。我大多是Java新手,這是一個基於用戶的異常處理程序。沒有合適的構造函數發現異常(int)

import java.util.*; 
class invalidbal extends Exception{ 
    invalidbal (int balance, int transaction){ 
    super(balance); 
    super(transaction); 
} 
class TestCustomException1{ 

static void validate(int balance, int transaction)throws invalidbal{ 
     if(balance - transaction < 0) 
      throw new InvalidAgeException("You are not eligible to Transact"); 
     else 
      System.out.println("Post transaction your current balance is" + (balance - transaction)); 
} 

public static void main(String args[]){ 
Scanner s = new Scanner(System.in); 
     System.out.println("Welcome to transaction checker"); 
    System.out.println("Please enter the balance:"); 
    a = s.nextInt(); 
    System.out.println("Please enter the transaction:"); 
    b = s.nextInt(); 
     try{ 
      validate(a,b); 
     }catch(Exception m){System.out.println("Exception occured: "+m);} 

    System.out.println("Thank you for checking!"); 
     } 
    } 
} 

輸出如下。

[email protected]:~$ javac bal.java 
bal.java:4: error: no suitable constructor found for Exception(int) 
    super(balance); 
    ^
    constructor Exception.Exception(String) is not applicable 
     (argument mismatch; int cannot be converted to String) 
    constructor Exception.Exception(Throwable) is not applicable 
     (argument mismatch; int cannot be converted to Throwable) 
bal.java:5: error: call to super must be first statement in   constructor 
    super(transaction); 
    ^
bal.java:9: error: Illegal static declaration in inner class  invalidbal.TestCustomException1 
    static void validate(int balance, int transaction)throws invalidbal{ 
      ^
    modifier 'static' is only allowed in constant variable declarations 
bal.java:20: error: cannot find symbol 
     a = s.nextInt(); 
     ^
    symbol: variable a 
    location: class invalidbal.TestCustomException1 
bal.java:22: error: cannot find symbol 
     b = s.nextInt(); 
     ^
    symbol: variable b 
    location: class invalidbal.TestCustomException1 
bal.java:24: error: cannot find symbol 
       validate(a,b); 
         ^
    symbol: variable a 
    location: class invalidbal.TestCustomException1 
bal.java:24: error: cannot find symbol 
       validate(a,b); 
        ^
    symbol: variable b 
    location: class invalidbal.TestCustomException1 
bal.java:16: error: Illegal static declaration in inner class invalidbal.TestCustomException1 
    public static void main(String args[]){ 
       ^
    modifier 'static' is only allowed in constant variable declarations 
Note: Some messages have been simplified; recompile with - Xdiags:verbose to get full output 
8 errors 
+0

在這裏你去https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html#constructor_summary - 選擇一個新的構造函數來使用 –

+0

並選擇*一個*缺點tructor。你不能兩次調用super。 –

+0

[Java找不到合適的構造函數]的可能重複(http://stackoverflow.com/questions/31354110/java-no-suitable-constructor-found) –

回答

0

進入每在Java文檔here沒有用於Exception類沒有構造函數輸入作爲int代碼hereAs,所以你得到這些錯誤:從invalidbal()構造

刪除follwoing行代碼

super(balance); 
super(transaction); 
相關問題