Incompatible types error on a for loop

Hi. I am in the middle of making a program and a decided to make a print statment to check to make sure everything was organized as it should be and I got an incompatible types error for the line where I start my for loop - for (index = 0 ...) etc. Since everything is an int, I'm not sure how they're not compatible with each other.. thoughts? here's my code so far, thanks
import java.io.*; // needed for stream readers
import java.lang.*;
public class testScores extends Object
     public static void main(String args[] ) throws Exception
     // declare variables for input
String      records;
String      room_nbr_input;
String      test_score_input;
String      student_id;
int          room_nbr_nbr;
int          test_score_nbr;
int          index;
String[] record = new String[3];
int[]     room_nbr = new int[30];
int[]      test_score = new int[30];
int[]     kount = new int[30];
     // created file reader and buffered reader
          FileReader frM;
          BufferedReader brM;
          // open file
          frM = new FileReader("einstein_testscores_2009.txt");
          brM = new BufferedReader(frM);
     // print headings
          startUp();
          // get one record from file
          records = brM.readLine();
          while(records !=null)
          //split the record into three fields = the array record[], then assign those values to variables
          record = records.split(", ");
          student_id = record[0];
          room_nbr_input = record[1];
          test_score_input = record[2];
          //change the data into integers
          room_nbr_nbr = Integer.parseInt(room_nbr_input);
          test_score_nbr = Integer.parseInt(test_score_input);
          //put the variables into arrays
          room_nbr[room_nbr_nbr -1] = room_nbr_nbr;
          test_score[room_nbr_nbr -1] = test_score[room_nbr_nbr -1] + test_score_nbr;
          //get new record
          records = brM.readLine();
          for (index = 0; index = room_nbr.length; index++)
               System.out.print(room_nbr[index] + "\t\t" + test_score[index]);
     public static void startUp()
     System.out.print("Einstein Elementary Test Scores\n\n");
     System.out.print("Room Number\t\tTest Score Average\n\n");
}          // end of class declaration

thank you. here's the code.
import java.io.*;       // needed for stream readers
import java.lang.*;   
public class testScores extends Object
     public static void main(String args[] ) throws Exception
     // declare variables for input
        String      records;
        String      room_nbr_input;
        String      test_score_input;
        String      student_id;
        int             room_nbr_nbr;
        int             test_score_nbr;
        int          index;
        String[] record = new String[3];
        int[]      room_nbr = new int[30];
        int[]       test_score = new int[30];
        int[]      kount = new int[30];
          // created file reader and buffered reader
          FileReader frM;
          BufferedReader brM;
          // open file
          frM = new FileReader("einstein_testscores_2009.txt");
          brM = new BufferedReader(frM);
     // print headings
          startUp();
          // get one record from file
          records = brM.readLine();
          while(records !=null)
          //split the record into three fields = the array record[], then assign those values to variables
          record = records.split(", ");
          student_id = record[0];
          room_nbr_input = record[1];
          test_score_input = record[2];
          //change the data into integers
          room_nbr_nbr = Integer.parseInt(room_nbr_input);
          test_score_nbr = Integer.parseInt(test_score_input);
          //put the variables into arrays
          room_nbr[room_nbr_nbr -1] = room_nbr_nbr;
          test_score[room_nbr_nbr -1] = test_score[room_nbr_nbr -1] + test_score_nbr;
          //get new record
          records = brM.readLine();
           for (index = 0; index = room_nbr.length; index++)
                System.out.print(room_nbr[index] + "\t\t" + test_score[index]);
     public static void startUp()
     System.out.print("Einstein Elementary Test Scores\n\n");
     System.out.print("Room Number\t\tTest Score Average\n\n");
}          // end of class declaration

Similar Messages

  • Illegal start of type error when adding for loop to applet

    I have typed the following applet to print a horizontal row of stars with the length entered by the user (i.e. user enters 4 and applet prints out 4 stars in a row). Here is my code:
    import java.awt.Graphics;
    import javax.swing.*;
    public class Histograms extends JApplet
           String input = "";
            int number;
         public void init()
              input = JOptionPane.showInputDialog ( null,
              "Enter a number\nbetween 1 and 30:" );
              number = Integer.parseInt( input );
         public void paint ( Graphics g )
              for ( int counter = 1; counter <= number; counter++ )
                                    System.out.print( "*" );
               System.out.println();
    };Now I am trying to make it do this 5 times, so it seems like just surrounding the init and paint methods in a for loop (i.e. for ( int i=1; i <= 5; i++ ) ) would do the trick but when I do that I get an illegal start of type error when trying to compile. Does anyone know why this error would show up. The most common reply to questions of this sort seems to be to check the closing braces but I have checked very carefully after adding the for loop and don't see any problems with mismatched braces. Could you please help me get on the right track as to how I can make this applet print a horizontal row of stars five times? All help is appreciated.

    Hello JTMOBOP:
    You were correct in figuring that I was trying to get the applet to print five rows of stars of different length according to five different inputs from the user. I tried your suggestions, and the code now does compile and run, but it still does not run properly (i.e. only asks user once for input and displays row of stars but does not show an input dialog again). Here is the code I have retyped:
    import java.awt.Graphics;
    import javax.swing.*;
    public class Histograms extends JApplet
       String input = "";
       int[] number = new int[5];
       public void init()
          for ( int i = 0; i < 5; i++ )
             input = JOptionPane.showInputDialog ( null,
                "Enter a number\nbetween 1 and 30:" );
             number[i] = Integer.parseInt( input );
       public void paint ( Graphics g )
          for ( int i = 0; i < 5; i++ )
             for ( int myNumber = 0; myNumber <= number; myNumber++ )
    System.out.print( "*" );
    System.out.println();
    Any ideas what's going on here?
    Also, your comments about not being able to loop a method make sense. Thank you for the input so far.

  • Incompatible type error

    I am receiving the following errors:
    incompatible types
    found: int
    required: boolean
    if (accessCode = 8345)
    if (accessCode = 55875)
    if (accessCode = 999909)
    I do not understand why I am getting the errors. accessCode is of type int.
    Thanks in advance for any input.
    int accessCode = Integer.parseInt( String.valueOf(
      securityCodeJPasswordField.getPassword() ) );
         int code;
         if (accessCode >= 1645 && accessCode <= 1689)
             code = 1;
         else
         if (accessCode  = 8345)
                code = 2;
         else
         if (accessCode = 55875)
             code = 3;
         else
         if (accessCode = 999898)
             code = 4;
         else
         if (accessCode >= 1000006 && accessCode <= 1000008)
             code = 5;
         else
         if (accessCode < 1000)
             code = 6;
         else
                        code = accessCode;

    Thanks !! I am stuck in the coding syntax that I use in my job: SAS

  • Incompatible types error....plzz help

    the code is
    import java.util.*;
    class a{
    public static void main(String args[]){
    LinkedList list = new LinkedList (  ) ; 
    list.add ( "shiva" ) ; 
    list.add ( "java" ) ; 
    list.add ( "world" ) ; 
    String [  ]   str = list.toArray ( new String [ list.size (  )  ]  ) ;
    }}the error is
    C:\Documents and Settings\Sumit\Desktop>javac a.java
    a.java:11: incompatible types
    found : java.lang.Object[]
    required: java.lang.String[]
    String [  ] str = list.toArray ( new String [ list.size (  )  ] ) ;
    ^
    Note: a.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    i am not getting what's wrong with it

    i am not getting what's wrong with itYou're not going to like this advice, but still you must learn to help yourself. If you've not done so, please look at the API on the LinkedList toArray method. If it doesn't make sense to you, then ask specific questions about what in the API you don't understand.

  • Error CreateImage in for loop array

    Hi,
    I would like to dynamically create images inside a for loop. It dependent on the array_size that the sevlets will send. Snapshots of code:
    for (int i = 0; i < ARRAY_SIZE; i++)
    img[i] = Image.createImage("\"/nike" + (i+1) + ".png\"");
    }Error:
    java.io.IOException
         at javax.microedition.lcdui.ImmutableImage.getImageFromStream(+15)
         at javax.microedition.lcdui.ImmutableImage.<init>(+20)
         at javax.microedition.lcdui.Image.createImage(+8)
         at SlidesCanvas.createImages(+138)
         at SlidesCanvas.<init>(+146)
         at ListSlides.commandAction(+113)
         at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
         at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
         at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
         at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
         at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
    Is this a known bug in CreateImage? Or am i doing it in a wrong way?

    Herlena
    I tried this, it works.
    for (int i = 0; i < ARRAY_SIZE; i++) {
        img[i] = img.createImage("nike" + (i+1) + ".png");
    Hope your problem is solved, Darryl

  • Having errors in basic for loop

    Folks
    I am tring to write SQL script that implements a block that contains a for-loop which increments a counter from 1 to 10 and inserts the counter value into the results field of the LOOPING table that i have created. i want to insert a null val in place of the counter if the counter value is equal to either 6 or 8.
    Below are my work
    Table creation
    CREATE TABLE LOOPING (Result VARCHAR2(60));
    I am expecting a output like this
    Result
    1
    2
    3
    4
    5
    NULL
    7
    Null
    9
    10
    My SCRIPT
    BEGIN
    FOR COUNTER IN 1..10
    IF ((COUNTER = 6 ) AND (COUNTER = 8 ))
    THEN
    INSERT INTO MESSAGES
    VALUES(NULL);
    ELSE
    INSERT INTO MESSAGES
    VALUES(COUNTER);
    END LOOP;
    END;
    I am getting errors. I am a beginner . Please help me out .
    can you point out my errors and explain
    And finaly please tell me how to correct it .
    Thanks
    Guna

    1) When you get an error, it's always helpful to post the details of that error (the error number and the line number). That makes it far easier for us to help you.
    2) Thank you for posting your code and table definition. That definitely helps! In the future, you'll want to use the \ tag (6 characters, all lower case) before and after any code fragments to preserve the white space & indentation.  That makes your code far easier to read.
    3) Your code fails to compile because
    - you are missing the LOOP keyword between lines 2 and 3
    - you are missing the END IF at the end of your IF statement
    - you are referring to a table named MESSAGES while your CREATE TABLE statement refers to a table named LOOPING
    If you correct those three errors, your code will compile
    [code]
    SQL> ed
    Wrote file afiedt.buf
      1  BEGIN
      2    FOR COUNTER IN 1..10
      3    LOOP -- Added
      4      IF ((COUNTER = 6 ) AND (COUNTER = 8 ))
      5      THEN
      6        INSERT INTO looping -- Changed table name
      7          VALUES(NULL);
      8      ELSE
      9        INSERT INTO looping -- Changed table name
    10          VALUES(COUNTER);
    11      END IF; -- Added
    12    END LOOP;
    13* END;
    SQL> /
    PL/SQL procedure successfully completed.
    [/code]
    4) However, now that the code compiles, you'll have a problem that it does not meet the requirements.  It will never insert a NULL value because your IF condition is incorrect.  Since this looks like a homework problem, however, I don't want to completely give it away-- I've probably done more than I should have already.
    Justin                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • BUG: 10.1.3..36.73 Internal Compile Error with enhanced for loop/generics

    I get the following compiler error when using the Java 5 SE enhanced for loop with a generic collection.
    Code:
    public static void main(String[] args)
    List<Integer> l = new ArrayList<Integer>();
    l.add(new Integer(1));
    printCollection(l);
    private static void printCollection(Collection<?> c)
    for (Object e : c)
    System.out.println(e);
    Error on attempting to build:
    "Error: Internal compilation error, terminated with a fatal exception"
    And the following from ojcInternalError.log:
    java.lang.NullPointerException
         at oracle.ojc.compiler.EnhancedForStatement.resolveAndCheck(Statement.java:2204)
         at oracle.ojc.compiler.StatementList.resolveAndCheck(Statement.java:4476)
         at oracle.ojc.compiler.MethodSymbol.resolveMethod(Symbol.java:10822)
         at oracle.ojc.compiler.RawClassSymbol.resolveMethodBodies(Symbol.java:6648)
         at oracle.ojc.compiler.Parser.resolveMethodBodies(Parser.java:8316)
         at oracle.ojc.compiler.Parser.parse(Parser.java:7823)
         at oracle.ojc.compiler.Compiler.main_internal(Compiler.java:978)
         at oracle.ojc.compiler.Compiler.main(Compiler.java:745)
         at oracle.jdeveloper.compiler.Ojc.translate(Ojc.java:1486)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildGraph(UnifiedBuildSystem.java:300)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildProjectFiles(UnifiedBuildSystem.java:515)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.buildAll(UnifiedBuildSystem.java:715)
         at oracle.jdeveloper.compiler.UnifiedBuildSystem$CompileThread.run(UnifiedBuildSystem.java:893)

    Install the Service Update 1 patch for JDeveloper (using the help->check for updates), and let us know if this didn't solve the problem.

  • Compile Error in Enhanced For Loop

    I'm learning generic collections and for practice wrote a simple class that uses a HashMap to store data. However, I'm getting a compile error for the code that accesses the HashMap. The error and code for my class follow.
    Can anyone help?
    Thanks...
    =====================
    The compile error:
    =====================
    MapDict.java:37: package Map does not exist for( Map.Entry entry : glossary.entrySet()  )                        ^1 error=======================
    The code for my class:
    =======================
    import java.util.Scanner;
    import java.util.HashMap;
    public class MapDict
         HashMap<String, String> glossary = new HashMap<String, String>();
         public void getEntries()
              Scanner sc = new Scanner( System.in ).useDelimiter("\n");
              String moreEntries = "y";
              String word        = "";
              String definition  = "";
              while ( moreEntries.toUpperCase().equals( "Y") )
                   System.out.print("Enter word: ");
                   word = sc.next();
                   System.out.print("Enter definition: ");
                   definition = sc.next();
                   glossary.put( word, definition);
                   System.out.print("Another glossary item? (y/n) ");
                   moreEntries = sc.next();
         public void displayEntries()
              System.out.println( glossary.size() );
              // Here is where the compile error occurs:
              for( Map.Entry entry : glossary.entrySet()  )
                   System.out.println( "\nWord: " + entry.getKey() + " Definition: " + entry.getValue() );
    }

    import java.util.Scanner;
    import java.util.HashMap;I don't see java.util.Map or java.util.Map.Entry listed here....

  • Incompatible types error in instanceof operator

    inconvertible types error. I have no idea why???
    class A
    class B
    public class Test2
    public static void main(String[] args)
    {     A a = new A();
         B b = new B();
    if (b instanceof A) System.out.println("b is child of A");
         if (a instanceof B) System.out.println("a is child of B");

    The compiler can tell that a isn't an instance of B and b isn't an instance of A. It doesn't need to wait until runtime. So it doesn't waste any time, it tells you that.

  • Error in cursor for loop

    Hi  Guys ,
    I am getting the below error in the following piece of code.I am using 11g.
           L_SQL_TXT:='begin'||CHR(32)||
          'for i in ( select '||l_col_list_1||', :in_tst_nm, :l_current_schema  from '||in_src_table||') LOOP
            insert into '||get_test_schema||'.'||in_src_table||' values('||l_col_list_2||',TEST_NM , TEST_CREATED_BY);
          end LOOP;
          end;';
          dbms_output.put_line (l_sql_txt);
          EXECUTE IMMEDIATE l_sql_txt USING in_sav_nm,l_current_schema;
          dbms_output.put_line (SQL%ROWCOUNT || ' test records added');
           I am getting the below error
    Error report:
    ORA-06550: line 3, column 95:
    PL/SQL: ORA-00984: column not allowed here
    ORA-06550: line 3, column 7:
    PL/SQL: SQL Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    What am i doing wrong? Please suggest

    Raunaq wrote:
             insert into '||get_test_schema||'.'||in_src_table||' values('||l_col_list_2||',TEST_NM , TEST_CREATED_BY);
    This insert statement doesn't look good! As you just passed TEST_NM and TEST_CREATED_BY as in a string. Those must have some values associated with!
    Like:- If those 2 are variables then it should be like :-
    -- For testing purpose with output !!!
    --- Added static values for references for the dynamic block
    Declare
    l_sql_txt varchar2(32767);
    get_test_schema varchar2(20) := 'scott';
    in_src_table varchar2(20) := 'src_tbl';
    l_col_list_1 varchar2(20) := 'col_name_1';
    l_col_list_2 varchar2(20) := 'col_name_2';
    test_nm varchar2(20) := 'Testing';
    test_created_by date :=sysdate ;
    begin
      l_sql_txt:='begin'||chr(32)||
          'for i in ( select '||l_col_list_1||', :in_tst_nm, :l_current_schema  from '||in_src_table||')
       loop
            insert into '||get_test_schema||'.'||in_src_table||' values('||l_col_list_2||','''||test_nm||''','''||test_created_by||''');
          end loop;
          end;';
       dbms_output.put_line ('sql text- '||l_sql_txt);
       --execute immediate l_sql_txt using in_sav_nm,l_current_schema;
          dbms_output.put_line (sql%rowcount || ' test records added');
    end;
    My OutPut looks like:-
    sql text- begin for i in ( select col_name_1, :in_tst_nm, :l_current_schema
    from src_tbl)
              loop
            insert into scott.src_tbl
    values(col_name_2,'Testing','04-JUL-13');
          end loop;
          end;
    test records added
    PL/SQL procedure successfully completed.

  • How to handle error within a FOR loop

    Hi all,
    For the code:
    begin
        for vc1 in (select *
                      from xx_primavera_invoices_detail
                     where transfered_to_ar = 0
                       and cust_trx_type_id not in (1000, 1003, 1016, 1023, 1040)
                       and act_end_date is not null) loop
          insert_into_ar_interface(vc1.amount, vc1.uom_code, vc1.quantity, vc1.unit_standard_price, vc1.cust_trx_type_id
                                  ,vc1.description, vc1.interface_line_attribute1, vc1.interface_line_attribute2, vc1.interface_line_attribute3, vc1.service_code
                                  ,vc1.gl_date, vc1.orig_system_bill_address_id, vc1.orig_system_bill_customer_id, vc1.segment2, vc1.segment3,vc1.customer_name,vc1.payment_type,vc1.currency_code)
        end loop;
        update xx_primavera_invoices_detail
           set transfered_to_ar = 1
         where transfered_to_ar = 0
           and cust_trx_type_id not in (1000, 1003, 1016, 1023, 1040)
        end;I want to add an exception statement if there is no value returned in VC1. I guess i'll never go into the loop statement because no data found in VC1 but the UPDATE will be executed...
    Any ideas?
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    "CORE     11.1.0.7.0     Production"
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionThanks in advance,
    Bahchevanov.

    Hi,
    declare
      v_i_was_in_loop  boolean;
    begin
      v_i_was_in_loop ;= false;
      for cur in (select ..)
      loop
        null;
        v_i_was_in_loop := true;
      end loop; 
    if v_i_was_in_loop = true
    then
       update...
    end if;    
    end;

  • Abap - incompatible type error

    Hi Experts,
    I got the requirement to change spell_amount function module into Z_SPELL_AMOUNT Function module. Sap has givin some modifications in spell_amount function module. so i have done those changes in Z_SPELL_AMOUNT FM
    After changing the code... the errors says that INT_ZAHL and UP_ZIFFER are type incompatile
    please find the following code which i changed,
    in the below coding it is showing error in the following statement
    DO 15 TIMES VARYING up_ziffer FROM int_zahl0 NEXT int_zahl1
    In SPELL_AMOUNT function modue contains this ZIFFERN_IN_WORTEN subroutine
    Thanks in advance.
    Jeyanthi.

    Dear Dinesh,
    previously the variable declaration  was
    up_ziffer(1) TYPE c,
    in correction i have changed like
    up_ziffer(1) TYPE n,
    there is no correction with int_zahl.
    previousely that do statement was
    DO 15 TIMES
    then changed as per correction in the notes
    like below
    DO 15 TIMES VARYING up_ziffer FROM int_zahl0 NEXT int_zahl1.
    Thanks.
    Jeyanthi

  • Syntax error on a for loop

    I am getting an error on the first line of the for statement. It says I need a semicolon but I can't seem to correct it and I know the error might not necessarily be on that line. I'm not sure how this even is going to print at the end of the switch statement but i can't compile it to find out. I can show you in another post what i am trying to achieve if it will help. Thanks.
    import javax.swing.*;
    import java.text.*;
    public class printNum
    public static void main (String [] args) {
    String startNumStr, endNumStr;
    int startNum, endNum;
    startNumStr= JOptionPane.showInputDialog(null, "Enter a starting number:");
    startNum = Integer.parseInt(startNumStr);
    endNumStr = JOptionPane.showInputDialog(null, "Enter an ending number:");
    endNum = Integer.parseInt(endNumStr);
    for(int startNum < endNum) {
    switch(startNum) {
    case startNum + 10:
    case startNum + 10:
    case startNum + 10: System.out.println(" " + startNum); break;
    default: System.out.println(" " + startNum);
    }

    I am getting an error on the first line of the for
    statement. It says I need a semicolon but I can't
    seem to correct it and I know the error might not
    necessarily be on that line. I'm not sure how this
    even is going to print at the end of the switch
    statement but i can't compile it to find out. I can
    show you in another post what i am trying to achieve
    if it will help. Thanks.
    import javax.swing.*;
    import java.text.*;
    public class printNum
    public static void main (String [] args) {
    String startNumStr, endNumStr;
    int startNum, endNum;
    startNumStr=
    tNumStr= JOptionPane.showInputDialog(null, "Enter a
    starting number:");
    startNum = Integer.parseInt(startNumStr);
    endNumStr = JOptionPane.showInputDialog(null,
    og(null, "Enter an ending number:");
    endNum = Integer.parseInt(endNumStr);
    for(int startNum < endNum) {
    switch(startNum) {
    case startNum + 10:
    case startNum + 10:
    case startNum + 10:
    e startNum + 10: System.out.println(" " + startNum);
    break;
    default: System.out.println(" " +
    ut.println(" " + startNum);
    }Why do you have the same case 3 times in the switch? Also, I don't think you can have variable expressions in the switch statement cases. I think these need to be constants.
    RD-R
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Incompatibe type error can some please help stuck in rut

    found : double
    required: javax.swing.JTextField
    TotalIncomeField = (num1 + num2 + num3);
    try {
    double num1 = Double.parseDouble(LoansField.getText());
    double num2 = Double.parseDouble(WagesField.getText());
    double num3 = Double.parseDouble(OtherField.getText());
    double num4 = Double.parseDouble(RentField.getText());
    double num5 = Double.parseDouble(FoodField.getText());
    double num6 = Double.parseDouble(OtherField2.getText());
    String op1 = (String)LoanComboBox.getSelectedItem();
    String op2 = (String)WagesComboBox.getSelectedItem();
    String op3 = (String)OtherComboBox.getSelectedItem();
    String op4 = (String)RentComboBox.getSelectedItem();
    String op5 = (String)FoodComboBox.getSelectedItem();
    String op6 = (String)Other2ComboBox.getSelectedItem();
    //Below I am adding the loans, wages & other field so that it total correctly incompatible type error found below (1).
    (1) TotalIncomeField = (num1 + num2 + num3);
    (2) TotalSpendingField = (num4 + num5 + num6);
    //Here above I am adding the rent, food & other field so that it total correctly incompatible type error found above (2)
    double result = 0;
    if (op1.equals("Weekly"))
    result = num1 * 4.3333333;
    else if (op1.equals("Monthly"))
    result = num1;
    else if (op1.equals("Yearly"))
    result = num1 / 12;
    else if
    (op2.equals("Weekly"))
    result = num2 * 4.3333333;
    else if (op2.equals("Monthly"))
    result = num2;
    else if (op2.equals("Yearly"))
    result = num2 / 12;
    else if
    (op3.equals("Weekly"))
    result = num3 * 4.3333333;
    else if (op3.equals("Monthly"))
    result = num3;
    else if (op3.equals("Yearly"))
    result = num3 / 12;
    TotalIncomeField.setText(String.format("%.2f",result));
    if
    (op4.equals("Weekly"))
    result = num4 * 4.3333333;
    else if (op4.equals("Monthly"))
    result = num4;
    else if (op4.equals("Yearly"))
    result = num4 / 12;
    else if
    (op5.equals("Weekly"))
    result = num5 * 4.3333333;
    else if (op5.equals("Monthly"))
    result = num5;
    else if (op5.equals("Yearly"))
    result = num5 / 12;
    else if
    (op6.equals("Weekly"))
    result = num6 * 4.3333333;
    else if (op6.equals("Monthly"))
    result = num6;
    else if (op6.equals("Yearly"))
    result = num6 / 12;
    TotalSpendingField.setText(String.format("%.2f",result));
    } catch (NumberFormatException ex) {
    }

    TotalIncomeField is a JTextField object reference, not a numeric value holder. What you may want is to put the string representation of the calculation into the CONTENTS of the JTextField. There is a setText method for that.
    TotalIncomeField.setText(theText);
    I'll assume you can work out how to turn the calculation into a string representing that calculation.
    SIGH SIGH SIGH
    Thanks for CROSSPOSTING this, you dolt.
    http://forum.java.sun.com/thread.jspa?threadID=780703

  • Incompatible types bug

    I have a problem with one of my method calls. It is saying there is an incompatible type. Here is the error message.
    "BalanceChecker.java": incompatible types; found : java.lang.Integer, required: int at line 28, column 26
    Here is the line line with the problem
    int inputLength = 0;
    inputLength = bc.getLength(input); <=====
    And here is the method
    public Integer getLength(String line)
    int length = 0;
    length = line.length();
    return length;
    Can someone tell me what is incompatible here.

    Hi all,
    I wanted to delete files older than a day, below is the code I have compiled but I am getting incompatible type error....Please any one help me out from this....
    Date t=null;
    Calendar rightNow = Calendar.getInstance();
    rightNow.add(Calendar.DATE-1);
    t = rightNow.getTime();
    Timestamp tm = new Timestamp(t);
    if (tm.before(getTimeStamp(filename)))
    {    del(......) ............................................}
    public static Timestamp getTimeStamp(String fileName) {
    File timestamp1 = new File(fileName);
    return(timestamp1.lastModified());
    }

Maybe you are looking for