Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android ListView
Hi ,
im getting exception on repopulating data on listview.
following is the code :
 
Quote:
@Override
public void run() {

// TODO Auto-generated method stub
if(ser.FindClients().interact.get(a).drive!=null){

//Log.e("FILEMANAGERACTIVITY", String.valueOf(ser.FindClients().interact.get(a).drive.size()));
fmd = new FileManagerAdaptor(FileManagerActivity.this, R.layout.activity_item_layout, ser.FindClients().interact.get(a).drive);

lst.setAdapter(fmd);
lst.setOnItemClickListener(new OnItemClickListener() {
 
@Override
public void onItemClick(AdapterView View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
//Toast.makeText(this, text, duration)
TextView txt = (TextView)arg1.findViewById(R.id.lblName);
Log.e("FILEMANAGERACTIVITY", "Done");
tmp = (String) txt.getText();
itemPosition = arg2;


new Thread(){
 
@Override
public void run() {
// TODO Auto-generated method stub

ser.FindClients().interact.get(a).ListFiles(tmp, ser.FindClients().interact.get(a).fileType.get(itemPosition));
//while(ser.FindClients().interact.get(a).working!=false);
//fmd = new FileManagerAdaptor(FileManagerActivity.this, R.layout.activity_item_layout, ser.FindClients().interact.get(a).fileNames);
//lst.setAdapter(fmd);
//Log.e("FILEMANAGERACTIVITY", String.valueOf(ser.FindClients().interact.get(a).fileNames.size()));
 
fmd.Data(ser.FindClients().interact.get(a).fileNames);

fmd.notifyDataSetChanged();


Log.e("FILEMANAGERACTIVITY", "List notified data changed");
//lst.setAdapter(fmd);

}
}.start();


}
});

} else
{
Log.e("FILEMANAGERACTIVITY", "Dives null");
}

 

 

 

while the adaptor class is this :
 

Quote:
public List data=null;
private Context con = null;
int layoutId=0;

public FileManagerAdaptor(Context context, int textViewResourceId,List data) {

this.data = data;
this.con = context;
this.layoutId = textViewResourceId;
// TODO Auto-generated constructor stub
}
 

 
@Override
public int getCount() {
// TODO Auto-generated method stub

//return super.getCount();
return data.size();

}
 
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
//return super.getItem(position);
return data.get(position);
}
public void Data(ArrayList data)
{
this.data = data;
//notifyDataSetChanged();
}

 
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;

LayoutInflater inf =(LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi= inf.inflate(layoutId, parent, false);


Log.e("FILEMANAGERADAPTOR", data.get(position));
TextView tx = (TextView) vi.findViewById(R.id.lblName);
tx.setText(data.get(position));
return vi;
}
 
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
 
}
Posted 2-Jun-13 14:31pm
Comments
Amitosh Swain at 2-Jun-13 21:31pm
   
Exception details??
shanalikhan at 3-Jun-13 3:53am
   
following is the exception getting in logcat
 
06-03 12:52:21.055: E/AndroidRuntime(10768): FATAL EXCEPTION: Thread-908
06-03 12:52:21.055: E/AndroidRuntime(10768): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
06-03 12:52:21.055: E/AndroidRuntime(10768): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
 

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Multithreading issues... I see, the solution is mentioned in the exception itself. You can only modify the view in the thread you created it. Move this line out of the new thread
fmd.Data(ser.FindClients().interact.get(a).fileNames);
 
You need some concurrency utilities to solve this, such as Exchanger or Semaphore. Try to notify the main thread that a background operation has finished and data has been returned. Then set the data of the view in the main thread.
 
Here main thread means the thread that the thread that created the view.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100