Şimdi Ara

Java inner class problem

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
1 Misafir - 1 Masaüstü
5 sn
1
Cevap
0
Favori
99
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • combobox'a veri eklemeye çalışırken non-static variable jComboBox1 cannot be referenced from a static context hatası alıyorum


        private static String readUrl(String urlString) throws Exception {
    BufferedReader reader = null;
    try {
    URL url = new URL(urlString);
    reader = new BufferedReader(new InputStreamReader(url.openStream()));
    StringBuffer buffer = new StringBuffer();
    int read;
    char[] chars = new char[1024];
    while ((read = reader.read(chars)) != -1)
    buffer.append(chars, 0, read);

    return buffer.toString();
    } finally {
    if (reader != null)
    reader.close();
    }
    }
    public static class MySQLEntry {
    public String id;
    public static String ad;
    public String latitude;
    public String longitude;
    public String speed;
    public String hour;
    public String day;
    public String adres;
    public String resimyol;

    public String getId() { return id; }
    public static String getName() { return ad; }
    public String getlat() { return latitude; }
    public String getlon() { return longitude; }
    public String getspeed() { return speed; }
    public String gethour() { return hour; }
    public String getday() { return day; }
    public String getadres() { return adres; }
    public String getresim() { return resimyol; }

    }

    public static void main(String args[]) {

    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
    * For details seehttp://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClassName());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(KonumGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(KonumGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(KonumGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(KonumGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new KonumGoster().setVisible(true);

    String json = null;
    try {
    json = readUrl("http://url/"
    + "json.php");
    } catch (Exception ex) {
    Logger.getLogger(KonumGoster.class.getName()).log(Level.SEVERE, null, ex);
    }

    Gson gson = new Gson();

    MySQLEntry[] array = gson.fromJson(json, MySQLEntry[].class);
    for (MySQLEntry obj : array) {
    //MySQLEntry x =new MySQLEntry(obj.getName());

    jComboBox1.addItem(getName());

    System.out.println("ID: " +obj.getId());
    System.out.println("Ad: " +obj.getName());
    System.out.println("Latitude: " +obj.getlat());
    System.out.println("Longitude: " +obj.getlon());
    System.out.println("Speed: " +obj.getspeed());
    System.out.println("Saat: " +obj.gethour());
    System.out.println("Tarih: " +obj.getday());
    System.out.println("Açık Adres: " +obj.getadres());
    System.out.println("Harita Üzerinde: " +obj.getresim());
    }







  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.