Wątek przeniesiony 2016-06-10 13:56 z Java przez bogdans.

Pobieranie wartosci z klasy obiekt.

0

Mam taki problem że próbuje pobrać dane z Obiektu. Kiedy debuguje kod w obiekcie customer widać wszystkie jego pola poprawnie natomiast kiedy próbuje pobrać je pokazuje mi że mam 0 pól czy wie ktoś może w czym może być problem ??

public Object createValue() throws BasicException {
        Object[] customer = new Object[25];
        customer[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId;
        customer[1] = m_jTaxID.getText();
        customer[2] = m_jSearchkey.getText();
        customer[3] = m_jName.getText();
        customer[4] = m_jNotes.getText();
        customer[5] = m_jVisible.isSelected();
        customer[6] = Formats.STRING.parseValue(jcard.getText()); // Format to manage NULL values
        customer[7] = Formats.CURRENCY.parseValue(txtMaxdebt.getText(), 0.0);
        customer[8] = Formats.TIMESTAMP.parseValue(txtCurdate.getText()); // not saved
        customer[9] = Formats.CURRENCY.parseValue(txtCurdebt.getText()); // not saved
        
        customer[10] = Formats.STRING.parseValue(txtFirstName.getText());
        customer[11] = Formats.STRING.parseValue(txtLastName.getText());
        customer[12] = Formats.STRING.parseValue(txtEmail.getText());
        customer[13] = Formats.STRING.parseValue(txtPhone.getText());
        customer[14] = Formats.STRING.parseValue(txtPhone2.getText());
        customer[15] = Formats.STRING.parseValue(txtFax.getText());
       
        customer[16] = Formats.STRING.parseValue(txtAddress.getText());
        customer[17] = Formats.STRING.parseValue(txtAddress2.getText());
        customer[18] = Formats.STRING.parseValue(txtPostal.getText());
        customer[19] = Formats.STRING.parseValue(txtCity.getText());
        customer[20] = Formats.STRING.parseValue(txtRegion.getText());
        customer[21] = Formats.STRING.parseValue(txtCountry.getText()); 
        
        customer[22] = m_CategoryModel.getSelectedKey();
// JG 3 Oct 2013 - Customer image
        customer[23] = m_jImage.getImage();    
        
        
         
        

        
        
        return customer;
 
 
if(m_editorrecord.getClass().equals(CustomersView.class)){
                       
                           Object customer = m_editorrecord.createValue();
                        
                           Field[] fields = customer.getClass().getDeclaredFields();
                           
                           System.out.println(fields.length);
                         //  System.out.println(fields[1]);
                           for (Field field : fields) {
                               System.out.println("Nazwa = " + field.getName() + " wartość = " + field); 
                           }
                       
                       }

63fc136c8f.png

0

Przecież zmienna customer nie ma żadnych (jawnych) pól, to jest zwykła tablica.

0

Dobra to na jakiej zasadzie mogę z niej pobierać dane ??

0

??? Pętla for po tablicy.

0

Object[] customer = m_editorrecord.createValue();

System.out.println(customer[0]);
..itp

0

Na obiekcie nie działa metoda length ani iteracyjna wiec nadal nie za bardzo wiem jak miałbym te dane miał pobierać za pomocą pętli

24e0bbd58c.png

0

Metoda zwraca obiekt nie obiekt[]

0

Wstawiaj do postu kod, nie obrazki.

public Object[] createValue() throws BasicException
...
for(int i=0;i<customer.length;i++)

Kod nadaje się do wyrzucenia, utwórz klasę Customer z odpowiednimi polami.

0

Możesz też wykorzystać taką dziwną konstrukcję:

                           Object[] customer = (Object [])m_editorrecord.createValue();

                           for (Object ob : customer) {
                               System.out.println(ob); 
                           }

1 użytkowników online, w tym zalogowanych: 0, gości: 1