Results 1 to 5 of 5

Thread: Compiling error

  1. #1
    robbierut is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default Compiling error

    Hey,

    I am making a app for my school. The purpose is to give in a digit and give the table of it.

    my code is:
    Java Code:
    void button1_ActionPerformed(java.awt.event.ActionEvent event)
    	{
    		int aantal;
    		aantal = Integer.parseInt(textField1.getText());		
    		int tafel1;
    		tafel1 = aantal * 1;
    		int tafel2;
    		tafel2 = aantal * 2;
    		int tafel3;
    		tafel3 = aantal * 3;
    		int tafel4;
    		tafel4 = aantal * 4;
    		int tafel5;
    		tafel5 = aantal * 5;
    		int tafel6;
    		tafel6 = aantal * 6;
    		int tafel7;
    		tafel7 = aantal * 7;
    		int tafel8;
    		tafel8 = aantal * 8;
    		int tafel9;
    		tafel9 = aantal * 9;
    		int tafel10;
    		tafel10 = aantal * 10;
    	    String schrijven;
    	    schrijven = textArea1.setText( "1" + "x" + (String.valueOf(aantal)) + "=" + (String.valueOf(tafel1)));
    But when I try to compile it it give's an error that it cant convert Void to java.lang.string
    The problem is in the last line.

    Can someone help me to point out the problem and/or give the solution?

    Robbierut

  2. #2
    xmdx's Avatar
    xmdx is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    You don't need to write String.valueOf(aantal), because compiler makes it automayically. You can change
    schrijven = textArea1.setText( "1" + "x" + (String.valueOf(aantal)) + "=" + (String.valueOf(tafel1)));
    with
    textArea1.setText( "1x" + aantal + "=" + tafel1);

    Also, what do you want to do with string 'schrijven'?
    Last edited by xmdx; 11-24-2010 at 02:02 PM.

  3. #3
    robbierut is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Okay, Gonna try it as soon as i downloaded the files to my home computer.
    The purpose of the string "schrijven" is to write it to a textarea which produces the results of the table.

    so in the textfield should say:
    1 x (input) = (input * 1)
    2 x (input) = (input * 2)

    etc.

  4. #4
    xmdx's Avatar
    xmdx is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    You don't need it. Just write
    Java Code:
    textArea1.setText( "1 x" + aantal + " = " + tafel1);
    But if u still want to use additional variable, u can do it like this:
    Java Code:
    String newValue = "1 x" + aantal + " = " + tafel1;
    textArea1.setText(newValue);
    And stop giving your variables such strange names.

  5. #5
    robbierut is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the fast replies:)

    And about the strange names, im dutch... so the word schrijven means Write. So in dutch it isnt to strange.
    Also the word aantal means number. so you got like table of 5.

Similar Threads

  1. dos compiling error msg.
    By gatehrdy in forum New To Java
    Replies: 22
    Last Post: 09-01-2010, 01:06 AM
  2. Having error while compiling
    By Kodeee in forum New To Java
    Replies: 12
    Last Post: 03-17-2009, 12:08 PM
  3. Compiling error
    By lawksalih in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 08:26 PM
  4. Error during compiling
    By boy22 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 03:42 AM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •