문제

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.

도움이 되었습니까?

해결책 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());

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top