Question

I want to assign some data from a database to a jTable in Netbeans. Problem is that in the main form from the get method the customer column is named:

  public int getCustomeridCustomer() {
        return customeridCustomer;
    }

So I put the same name in the form that I'm building the Data Access Object.

Object[] objects = new Object[3];
if(l.size() > 0)
{
    for(int i = 0; i < l.size();i++)
    {
        Rentals hashmap = l.get(i);
        objects[0]=hashmap.getIdRentals().toString();
        objects[1]=hashmap.getCustomeridCustomer().toString();
        objects[2]=hashmap.getRentedDate().toString();
        amod.addRow(objects);
    }
    this.jTable1.setModel(amod);

But! Netbans says that "int cannot be dereferenced". Any help will gladly appreciated.

Was it helpful?

Solution 2

 objects[1]=hashmap.getCustomeridCustomer().toString();

You cannot dereference a primitive type variables like that - getCustomeridCustomer().toString().


Instead just do as following (as you seem to want to assign the string representation of the int primitive) -

objects[1]=String.valueOf(hashmap.getCustomeridCustomer());

OTHER TIPS

In this line

objects[1]=hashmap.getCustomeridCustomer().toString();

you are trying to invoke a method on a primitive type. In Java you can only invoke methods on classes and objects, not primitive types.

That's because method public int getCustomeridCustomer() returns an int, which is a primitive type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top