I read other posts but didnt solved my problem. I am newbie on Android. I have to connect to MSSQL but i am getting the original thread error. How can i solve this? Thanks.
Here is my code :
private class MyThread implements Runnable {
public void run() {
durumKontrol();
if (isConnected) {
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
kuyrukKontrol();
}
}).start();
} else {
Toast toast = Toast
.makeText(
getApplicationContext(),
"Ağa erişilemiyor. Lütfen kablosuz ağın açık olduğundan emin olunuz",
Toast.LENGTH_LONG);
toast.show();
}
tick_Handler.postDelayed(tick_thread, firstDelay);
firstDelay = 10000;
}
}private void kuyrukKontrol() {
// TODO Auto-generated method stub
// Hücrenin sipariş ettiği ve henüz getirilmemiş malzemelerin listesi
// çekiliyor
TextView tvIP = (TextView) findViewById(R.id.tvIP);
tvIP.setText(HatAdi + "-" + HucreNo);
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager
.getConnection("jdbc:jtds:sqlserver://x.x.x.x:1433",
"xx", "xxxxx");
Statement query = conn.createStatement();
// İlk olarak bu forklifte ait teslim edilmeyen bir talep var mı
ResultSet rs = query
.executeQuery("select * from MOBILE.dbo.fos_SS where hucreNo = '" + HucreNo + "' and sonDurum != 'T'");
while (rs.next()) {
KuyrugaEkle(rs.getString("malzemeNo"),rs.getString("sonDurum"),rs.getString("sonIslemZamani"));
}
rs.close();
conn.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and in KuyrugaEkle function i dynamically change the layout, and i am getting error in that function.
Thanks.
You are not allowed to modify the UI from thread other than main, and you do that in the function
kuyrukKontrol. UseHandlerorrunOnUiThreadto perform it on the main thread.