Arama butonu
Bu konudaki kullanıcılar: 1 misafir, 1 mobil kullanıcı
0
Cevap
106
Tıklama
0
Öne Çıkarma
Java inner class problem
S
8 yıl
Binbaşı
Konu Sahibi

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());
}

DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.

Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.

Üye Ol Şimdi Değil