Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: no idea what is wrong with this code

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default no idea what is wrong with this code

    had to fix this code for school, everyone now fixed every error they previously had and now everyone has the same errors and nobody can figure out why


    the code:
    import javafx.scene.Scene;
    import javafx.stage.Stage;
     
     
    import javafx.scene.layout.*;
    import javafx.scene.control.*;
    import javafx.scene.text.*;
     
     
     
    public class Opdracht1WEEE extends Application
    {
     
     
    	GridPane mijnGrid;
    	Scene scene;
     
    	Text scenetitle;
     
     
     
    	public void start(Stage primaryStage)
    	{
     
     
     
    		primaryStage.setScene(scene);
    		Scene scenE = new Scene(mijnGrid, 400, 250);
    		primaryStage.setTitle(titelTekst);
        primaryStage.show();
     
     
    		String titelTekst = "WEEE - Periode 1, Les 1";
     
     
    		Text scenetitel = new Text(titelTekst);
    		scenetitel.setFont(Font.font("Calibri", FontWeight.NORMAL, 30));
        mijnGrid.add(scenetitle, 0, 0, 2, 1);
     
    		Label vraag0 = new Label("Gefeliciteerd! Het werkt!");
        vraag0.setFont(Font.font("Arial", FontPosture.ITALIC, 20));
        mijnGrid.add(vraagO, 0, 1); mijnGrid = new GridPane();
     
    		for (char karakter : vraag0.getText(ToCharArray())) {
    			System.out.println(karakter);
    		}
     
    		System.out.println(vraag0.getText).replace(('!'),(' ') + ("nog niet helemaal"));
     
     
    		Label vraag1 = new Label("Hoe vond je de opdracht?");
    		TextField antwoord1 = new TextField();
        mijnGrid.add(vraag1, 0, 2);
    		mijnGrid.add(antwoord1, 1, 2);
     
     
     
    		Label vraag2 = new Label("Wat vond je lastig?");
    		mijnGrid.add(vraag2, 0, 3);
     
    		if (vraag.getText())toCharArray [0] = 'W';
    		{ CheckBox antwoord2A = new CheckBox("Spelling");
    			CheckBox antwoord2B = new CheckBox("Interpunctie");
          CheckBox antwoord2C = new CheckBox("Volgorde");
    			CheckBox antwoord2D = new CheckBox("Structuur & Layout");
    			mijnGrid.add(antwoordA, 1, 3);
    			mijnGrid.add(antwoord2B, 1, 4);
    			mijnGrid.add(antwoorb2D, 1, 6);
    			mijnGrid.add(antwoord2C, 1, 5);
        }
     
    		}
     
     
     
    	public static void main(String[] args)
    	{
     
     
    		int getalNummerA = -1;
     
     
     
    		if (args.length > 0) {
    			tekstEen = args[0].toString();
    		}
     
     
    		String tekstEen = "";
     
    		System.out.println(getalnummerA);
     
    		System.out.println("Hallo" + tekstEen);
     
     
    		if (magVerder && (getalNummerA == 0 || textEen.isEmpty()))
    		{
    			getalNumerA = Math.round( (20.0f  * (float)Math.random() ));
     
    			if (getalNummerA > 0) { launch(Args);
     
     
     
    		boolean magverder = true;
    		}
     
    	}
    }
    }


    the errors when compiling:
    D:\School\TPR CODE JAVA\CODE>javac Opdracht1WEEE.java
    Opdracht1WEEE.java:13: error: cannot find symbol
    public class Opdracht1WEEE extends Application
                                       ^
      symbol: class Application
    Opdracht1WEEE.java:31: error: cannot find symbol
                    primaryStage.setTitle(titelTekst);
                                          ^
      symbol:   variable titelTekst
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:44: error: cannot find symbol
        mijnGrid.add(vraagO, 0, 1); mijnGrid = new GridPane();
                     ^
      symbol:   variable vraagO
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:46: error: cannot find symbol
                    for (char karakter : vraag0.getText(ToCharArray())) {
                                                        ^
      symbol:   method ToCharArray()
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:50: error: cannot find symbol
                    System.out.println(vraag0.getText).replace(('!'),(' ') + ("nog niet helemaal"));
                                             ^
      symbol:   variable getText
      location: variable vraag0 of type Label
    Opdracht1WEEE.java:63: error: cannot find symbol
                    if (vraag.getText())toCharArray [0] = 'W';
                        ^
      symbol:   variable vraag
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:63: error: cannot find symbol
                    if (vraag.getText())toCharArray [0] = 'W';
                                        ^
      symbol:   variable toCharArray
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:68: error: cannot find symbol
                            mijnGrid.add(antwoordA, 1, 3);
                                         ^
      symbol:   variable antwoordA
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:70: error: cannot find symbol
                            mijnGrid.add(antwoorb2D, 1, 6);
                                         ^
      symbol:   variable antwoorb2D
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:87: error: cannot find symbol
                            tekstEen = args[0].toString();
                            ^
      symbol:   variable tekstEen
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:93: error: cannot find symbol
                    System.out.println(getalnummerA);
                                       ^
      symbol:   variable getalnummerA
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:98: error: cannot find symbol
                    if (magVerder && (getalNummerA == 0 || textEen.isEmpty()))
                        ^
      symbol:   variable magVerder
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:98: error: cannot find symbol
                    if (magVerder && (getalNummerA == 0 || textEen.isEmpty()))
                                                           ^
      symbol:   variable textEen
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:100: error: cannot find symbol
                            getalNumerA = Math.round( (20.0f  * (float)Math.random() ));
                            ^
      symbol:   variable getalNumerA
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:102: error: cannot find symbol
                            if (getalNummerA > 0) { launch(Args);
                                                           ^
      symbol:   variable Args
      location: class Opdracht1WEEE
    15 errors

    hope some of you know what is going on.

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: no idea what is wrong with this code

    You should set titelTekst as global.
    Whatever you are, be a good one

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    92
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: no idea what is wrong with this code

    Wow, with so many issues with that code this it's hard to know where to start.

    You're definitely missing an import statement:
    import javafx.application.Application;
    You're trying to use a variable 'titelTekst' before it's even declared:
    primaryStage.setTitle(titelTekst);
    primaryStage.show();
    String titelTekst = "WEEE - Periode 1, Les 1";
    You're trying to add 'vraagO' to the GridPane but you created the label with the name as 'vraag0' (with a zero, not upper-case O):
    mijnGrid.add(vraagO, 0, 1);
    You're calling a 'ToCharArray()' function that doesn't exist anywhere:
    for (char karakter : vraag0.getText(ToCharArray())) { // Should be 'vraag0.getText().toCharArray()'
    	System.out.println(karakter);
    }
    You're calling the getText() function of the label incorrectly:
    System.out.println(vraag0.getText).replace(('!'), (' ') + ("nog niet helemaal"));
    You're referencing a 'vraag' label that doesn't exist, and referencing a 'toCharArray' array that doesn't exist anywhere:
    if (vraag.getText()) {
    	toCharArray[0] = 'W';
    }
    You're creating CheckBoxes with names 'antwoord2A' and 'antwoord2D' but then you're misspelling the names when trying to use them:
    CheckBox antwoord2A = new CheckBox("Spelling");
    CheckBox antwoord2B = new CheckBox("Interpunctie");
    CheckBox antwoord2C = new CheckBox("Volgorde");
    CheckBox antwoord2D = new CheckBox("Structuur & Layout");
    mijnGrid.add(antwoordA, 1, 3); // NO, you named it 'antwoord2A' not 'antwordA'
    mijnGrid.add(antwoord2B, 1, 4);
    mijnGrid.add(antwoorb2D, 1, 6); // NO, you named it 'antwoord2D' not 'antwoorb2D'
    mijnGrid.add(antwoord2C, 1, 5);
    Your main() function also has references to variables and functions that don't exist (e.g. 'Args' instead of 'args', for one).

    I would start by adding the missing import statement and cleaning up the simple mistakes like variable name mismatches and using variables before they're defined. Once all that noise is gone, the remaining issues should be easier to isolate and fix.

  4. The Following User Says Thank You to BinaryDigit09 For This Useful Post:

    MLG_C00K1E (October 22nd, 2017)

  5. #4
    Junior Member
    Join Date
    Oct 2017
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: no idea what is wrong with this code

    Thanks, with your help i got it down to 4 errors. i am kinda stuck again tho :/

    code now:
     
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import javafx.application.Application;
     
     
    import javafx.scene.layout.*;
    import javafx.scene.control.*;
    import javafx.scene.text.*;
     
     
     
    public class Opdracht1WEEE extends Application
    {
     
     
    	GridPane mijnGrid;
    	Scene scene;
     
    	Text scenetitle;
     
     
     
    	public void start(Stage primaryStage)
    	{
     
     
     
    		primaryStage.setScene(scene);
    		Scene scenE = new Scene(mijnGrid, 400, 250);
    		String titelTekst = "WEEE - Periode 1, Les 1";
    		primaryStage.setTitle(titelTekst);
        primaryStage.show();
     
     
     
     
    		Text scenetitel = new Text(titelTekst);
    		scenetitel.setFont(Font.font("Calibri", FontWeight.NORMAL, 30));
        mijnGrid.add(scenetitle, 0, 0, 2, 1);
     
    		Label vraag0 = new Label("Gefeliciteerd! Het werkt!");
        vraag0.setFont(Font.font("Arial", FontPosture.ITALIC, 20));
        mijnGrid.add(vraag0, 0, 1); mijnGrid = new GridPane();
     
    		for (char karakter : vraag0.getText(toCharArray())) {
    			System.out.println(karakter);
    		}
     
    		System.out.println(vraag0.getText(replace(('!'),(' ') + ("nog niet helemaal"))));
     
     
    		Label vraag1 = new Label("Hoe vond je de opdracht?");
    		TextField antwoord1 = new TextField();
        mijnGrid.add(vraag1, 0, 2);
    		mijnGrid.add(antwoord1, 1, 2);
     
     
     
    		Label vraag2 = new Label("Wat vond je lastig?");
    		mijnGrid.add(vraag2, 0, 3);
     
    		if (vraag0.getText())toCharArray() [0] = 'W';
    		{ CheckBox antwoord2A = new CheckBox("Spelling");
    			CheckBox antwoord2B = new CheckBox("Interpunctie");
          CheckBox antwoord2C = new CheckBox("Volgorde");
    			CheckBox antwoord2D = new CheckBox("Structuur & Layout");
    			mijnGrid.add(antwoord2A, 1, 3);
    			mijnGrid.add(antwoord2B, 1, 4);
    			mijnGrid.add(antwoord2D, 1, 6);
    			mijnGrid.add(antwoord2C, 1, 5);
        }
     
    		}
     
     
     
    	public static void main(String[] args)
    	{
     
     
    		int getalNummerA = -1;
    		String tekstEen = "";
     
     
     
    		if (args.length > 0) {
    			tekstEen = args[0].toString();
    		}
     
     
     
    		System.out.println(getalNummerA);
     
    		System.out.println("Hallo" + tekstEen);
    		boolean magVerder = true;
     
     
    		if (magVerder && (getalNummerA == 0 || tekstEen.isEmpty()))
    		{
    			getalNummerA = Math.round( (20.0f  * (float)Math.random() ));
     
    			if (getalNummerA > 0) { launch(args);
     
     
     
    		}
     
    	}
    }
    }


    errors now:
    Opdracht1WEEE.java:47: error: cannot find symbol
                    for (char karakter : vraag0.getText(toCharArray())) {
                                                        ^
      symbol:   method toCharArray()
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:51: error: cannot find symbol
                    System.out.println(vraag0.getText(replace(('!'),(' ') + ("nog niet helemaal"))));
                                                      ^
      symbol:   method replace(char,String)
      location: class Opdracht1WEEE
    Opdracht1WEEE.java:64: error: incompatible types: String cannot be converted to boolean
                    if (vraag0.getText())toCharArray() [0] = 'W';
                                      ^
    Opdracht1WEEE.java:64: error: cannot find symbol
                    if (vraag0.getText())toCharArray() [0] = 'W';
                                         ^
      symbol:   method toCharArray()
      location: class Opdracht1WEEE
    4 errors

    i dont get how i use the replace() and toCharArray().

  6. #5
    Member
    Join Date
    Apr 2014
    Posts
    92
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: no idea what is wrong with this code

    vraag0.getText().toCharArray();
    vraag0.getText().replace("!", " ");

  7. The Following User Says Thank You to BinaryDigit09 For This Useful Post:

    MLG_C00K1E (October 27th, 2017)

Similar Threads

  1. [SOLVED] Boolean trouble, no idea whats wrong.
    By Cekeh in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2013, 07:13 PM
  2. Help! have no idea what's wrong with my code..
    By Zaki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 17th, 2012, 10:22 PM
  3. How do I expand this code? I have no idea what my teacher wants.
    By Eclecstatic in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 3rd, 2012, 10:18 PM
  4. Replies: 2
    Last Post: September 2nd, 2012, 02:06 PM
  5. Wrong code
    By whattheeff in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2011, 05:30 PM