#can't print object name

57 messages · Page 1 of 1 (latest)

rapid warren
#

I have code which when run makes (new Something();) using external java file (same package different java file) when I try and find it I get an error ```

operable program or batch file.``` I seem be able to create it
odd gorgeBOT
#

This post has been reserved for your question.

Hey @rapid warren! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

rapid warren
#

here is the code that Im using from controller class (which makes the object) and the class that is used

#
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;

public class Controller{
    @FXML
    TextField nameField, findField;

    @FXML
    <T> void showME(ActionEvent event) {
        //System.out.println(nameField.getText());
        testingclass temp = new testingclass<T>(nameField.getText());
        System.out.println(temp);
        //testingclass(nameField.getText());
        //testingclass.nope();


    }

    @FXML
    void findME(ActionEvent event) {
        //findField
        System.out.println(temp.name);
    }

}```
#
    String name;

    protected static void nope(){
        System.out.println("322");
    };

    testingclass(String name){
        this.name = name;
        //System.out.println(testingclass.this.name);
    }
}
#

is there a way I can call testingclass<T> with Controller and find out the name of that class?

rapid warren
#

.

slender ocean
#

You mean create an object of type testingClass and get the name variable?

#

If so then

System.out.println(temp.name);

provided the 2 classes are in the same package

#

If they aren't in the same package then have a getter

rapid warren
#

both are in the same package, and it seems I am able to create different objects as the memory parameter is different always

rapid warren
#

I want to - once I pressed a button - add an object to a red area and be able to select and edit it

slender ocean
rapid warren
#
Aug 29, 2023 4:19:37 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 19 by JavaFX runtime of version 17
com.example.testingclass@3076f4e8```
#

I pressed the Create button and it gave me com.examples...
I pressed Show and nothing happened

slender ocean
#

Its printing out com.example.... because you are printing out the testingClass object instead of the testingClass name field

rapid warren
#
    <T> void showME(ActionEvent event) {
        //System.out.println(nameField.getText());
        testingclass temp = new testingclass<T>(nameField.getText());
        System.out.println(temp);
        //testingclass(nameField.getText());
        //testingclass.nope();
       // Label label = new Label();


    }

    @FXML
    void findME(ActionEvent event) {
        //findField
        System.out.println(temp.name);
        //System.out.println( getClass().getSimpleName());
    }```
#

showME is what makes a object and shows me that it made it

findME is what is supposed to show me an object that was made once I input the name of an object im searching for

odd gorgeBOT
#
@FXML
<T> void showME(ActionEvent event) {
	//System.out.println(nameField.getText());
	testingclass temp = new testingclass<T>(nameField.getText());
	System.out.println(temp);
	//testingclass(nameField.getText());
	//testingclass.nope();
	// Label label = new Label();
	
	
}

@FXML
void findME(ActionEvent event) {
	//findField
	System.out.println(temp.name);
	//System.out.println( getClass().getSimpleName());
}
rapid warren
#

😮 how did you do that?

slender ocean
#
System.out.println(temp);
rapid warren
odd gorgeBOT
# rapid warren THANK YOU!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

rapid warren
#

the fundME should search for that place and display that object

slender ocean
#

You are not storing the objects anywhere so how do you want to search for it?

rapid warren
#

am not? but... I made it

slender ocean
#
testingclass temp = new testingclass<T>(nameField.getText());

This creates an object, and assigns it to the temp variable. Maybe you want to store them in an object variable array or something so that they are shown?

rapid warren
#

yes, I want to store them and display in future after they are created... which I thought I did

#

I tried to use generics like <T> but I feel like I messed up

slender ocean
#

Yeah theres no need for generics

#

How about you have an object variable List of testingClass objects. Everytime you click create, add to that list. Then go through each object in the list, get all the names and set the textfield to the names

lapis joltBOT
#

so... something like...
list<> List = [];

object(){}

createObj(obj name){
List[list.length] = obj name;
} ```

This message has been formatted automatically. You can disable this using /preferences.

rapid warren
#

😐

#

I didn't finish but something like that^?

slender ocean
#
List<testingClass> myObjects = new ArrayList<testingClass>();

@FXML
void showME(ActionEvent event) {
    testingclass temp = new testingclass(nameField.getText());
    System.out.println(temp);
    myObjects.add(temp);
    String str = getNameList();
    //here - set the testfield to the string str
}

private String getNameList() {
  String objectString = "";
  for (TestingClass object: myObjects) {
    objectString += object.name + "\n";
  }
  return objectString;
}

@FXML
void findME(ActionEvent event) {
  String str = getNameList();
  //here - set the testfield to the string str
}
rapid warren
#

can I be honest with you?

#

I don't fully understand what "<TestingClass>" in first line does...

slender ocean
#

Its just saying that the list is a list of testingClass objects

#

I Fixed up the code a little

rapid warren
#

so... if I want to call a ... ?variable? ...from myObjects and change a specific aspect of it. will I be able to?

slender ocean
#

You mean if you want to get an object from the list and change a property of the object?

lapis joltBOT
#

myObject[1] = variable1

variable1 {
name: "here",
type: 7
container: "label"
} ```

This message has been formatted automatically. You can disable this using /preferences.

slender ocean
#

myObjects.get(index) retreives an object from the list at the specified index

rapid warren
#

can I go myObj[1]. name = "new name goes here"?

slender ocean
#

you can do

myObjects.get(0).name = "anything";
#

If it was an array and not a list, then you could have done

myObjects[0].name = "anything";
rapid warren
#

._. I feel like I should know this... before even thinking of getting into gui and stuff

slender ocean
#

Without meaning to sound rude you need to brush op on core java

rapid warren
#

thank you, I will

odd gorgeBOT
# rapid warren thank you, I will

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

slender ocean
rapid warren