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 6 of 6

Thread: [ASK]Array required, but java.lang.Object Found

  1. #1
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy [ASK]Array required, but java.lang.Object Found

    Greetings all, there is an error "Array required, but java.lang.Object Found" please its support. ..

    This coding it :

    public void loadData() {
    //Menghapus seluruh data
    model.getDataVector().removeAllElements();
    //Memberitahu data telah kosong
    model.fireTableDataChanged();

    try {
    Connection c = (Connection) KoneksiDatabase.getKoneksi();
    Statement s = c.createStatement();
    String sql = “select * from mahasiswa”;
    ResultSet r = s.executeQuery(sql);

    while(r.next()) {
    //Lakukan penelusuran baris
    Object o = new Object[5];
    o[0] = r.getString(“Nim”);
    o[1] = r.getString(“Nama”);
    o[2] = r.getDate(“Tanggal_Lahir”);
    o[3] = r.getString(“Jurusan”);
    o[4] = r.getString(“Alamat”);

    model.addRow(o);
    }

    r.close();
    s.close();
    } catch (SQLException e) {
    System.out.println(“Terjadi kesalahan proses Pengambilan Database”);
    }
    }

    Thanks before. ..


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: [ASK]Array required, but java.lang.Object Found

    Please use code tags nest time you post code.
    Make o an Array:
    Object[] o = new Object[5];

  3. #3
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: [ASK]Array required, but java.lang.Object Found

    You should cast in to an array like follows:
    model.addRow((Object[]) o);

  4. #4
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: [ASK]Array required, but java.lang.Object Found

    Why should he cast instead of using the proper data type in the first place?

  5. #5
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: [ASK]Array required, but java.lang.Object Found

    It's useful to know all possible solutions.

  6. #6
    Junior Member
    Join Date
    May 2013
    Location
    Indonesia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: [ASK]Array required, but java.lang.Object Found

    thanks all for your support. ..

Similar Threads

  1. help with array for creating and inserting reference to object in java
    By hiralmak in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2012, 07:01 AM
  2. java.lang.IllegalArgumentException: Identifier not found
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 9th, 2012, 04:48 AM
  3. "possible loss of precision, found double, required int" HELP
    By kkatchh in forum Loops & Control Statements
    Replies: 3
    Last Post: November 6th, 2011, 10:50 AM
  4. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM
  5. Urgent help required - converting image to array
    By Paulious in forum Algorithms & Recursion
    Replies: 0
    Last Post: September 1st, 2010, 06:24 AM

Tags for this Thread