Java compile error. Cannot Resolve symbol and incompatible types. HELP!! ASAP please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jatinmalhotra
    New Member
    • Feb 2015
    • 1

    #1

    Java compile error. Cannot Resolve symbol and incompatible types. HELP!! ASAP please

    Code:
    import java.io.*;
    class CAcc
    {
        String name[]=new String[15];
        long accno;
        char type;
        double Bal;
        
        CAcc(String Name,long Accno,char Type,double bal)
        { 
             
             name=Name;
             accno=Accno;
             type=Type;
             Bal=bal;
             System.out.println("New account created with provided details");
        } 
        void deposit(double amnt)
        {
             Bal=Bal+amnt;
             System.out.println("Amount deposited in Bank is"+amnt);
        }
         int withdraw(double amnt)
        {
            System.out.println("Old Balance in account is Rs."+Bal);
            if(Bal>=amnt)  
           {  
                Bal=Bal-amnt;
                System.out.println("New Balance in account is Rs."+Bal);
                return(0);
           }
            else
           {
                return(1);
           }    
        }
        void Check()
        {
            System.out.println("The Balance in Accno."+accno);
            System.out.println("The Balance is"+Bal);
        }
    }
    
    class Bank
    {
        public static void main(String []args)       
        {
            CAcc Manish= new CAcc ("Manish","200","S","15000.00");        
            Manish.Check();
            Manish.deposit(3000.00);
            Manish.withdraw(1500.00);
            Manish.Check();
        }
    }        
    
    My CODE is this and the error is here 
    
    Bank.java:22: incompatible types
    found : java.lang.String
    required:java.long.string[]
           name=Name
                ^
    Bank.java:58:cannot resolve symbol
    symbol: constructor CAcc(java.lang.String,Java.lang.string,java.lang.string,java.lang.String)
    location: class CAcc
        CAcc Manish=new CAcc("Manish","200","S","15000.00");
                    ^
    Last edited by Rabbit; Feb 9 '15, 02:46 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    In line 4 you define an array of strings, not a single string. Java is not like c++ wehre you have an array of chars as string. You just write
    Code:
    String name = "defaultValue"
    Then the compile error in line 12 would go away. In Line 12, you were trying to assign the string "Name" to this array, which does not work. You can only assign arrays to arrays or Strings to Strings, but not mix it. Therefore you got the compile error
    Code:
    Bank.java:22: incompatible types
    found : java.lang.String
    required:java.long.string[]
           name=Name
    By the way, please be polite. No need to shout help and make pressure by typing ASAP. It should be self-understanding that we do it for free and only if we have some spare time and nobody can force us to answer. That's different from work where you pay for. Usually I do not answer these types of requests (and nobody else would, too), but today I was just in a funny mood. So I give you a good advice: if you want some feedback in the future, omit that sentence!

    Comment

    Working...