android


Error while setting adapter for list-view Android


I am getting a weird error while setting up my adapter for listview in Android. I am developing a chat application, when i send any message it appears in listview, but when i try to receive the message it takes me to Catch-block in FutureTask class
I am using adapter.notifyDataSetChanged(); to let my adapter know of any change i am creating in the adapter.
My code is as follows
private void addNewMessage(MessageItems m) {
if(MainActivity.mymessage)
{
messages.add(m);
}else if(MainActivity.mymessage == false)
{
messages.add(m);
}
adapter.notifyDataSetChanged();
getListView().setSelection(messages.size()-1);
}
**Code of Adapter**
public class AwesomeAdapter extends BaseAdapter{
private Context mContext;
private ArrayList<MessageItems> mMessages;
public AwesomeAdapter(Context context, ArrayList<MessageItems> messages) {
super();
this.mContext = context;
this.mMessages = messages;
}
#Override
public int getCount() {
return mMessages.size();
}
#Override
public Object getItem(int position) {
return mMessages.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
MessageItems message = (MessageItems) this.getItem(position);
ViewHolder holder;
if(convertView == null)
{
holder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false);
holder.message = (TextView) convertView.findViewById(R.id.message_text);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.message.setText(message.getMessage());
LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
//check if it is a status message then remove background, and change text color.
if(message.isStatusMessage())
{
holder.message.setBackgroundDrawable(null);
lp.gravity = Gravity.LEFT;
holder.message.getResources().getColor(R.color.textFieldColor);
//holder.message.setTextColor(R.color.textFieldColor);
}
else
{
//Check whether message is mine to show green background and align to right
if(message.isMine())
{
holder.message.setBackgroundResource(R.drawable.speech_bubble_green);
lp.gravity = Gravity.RIGHT;
}
//If not mine then it is from sender to show orange background and align to left
else
{
holder.message.setBackgroundResource(R.drawable.speech_bubble_orange);
lp.gravity = Gravity.LEFT;
}
holder.message.setLayoutParams(lp);
holder.message.getResources().getColor(R.color.textFieldColor);
//holder.message.setTextColor(R.color.textColor);
}
return convertView;
}
private static class ViewHolder
{
TextView message;
}
#Override
public long getItemId(int position) {
//Unimplemented, because we aren't using Sqlite.
return position;
}
In FutureTask class it takes me to the following try-catch block when i try to set adapter.notifyDataSetChanged();
public void run() {
if (state != NEW ||
!UNSAFE.compareAndSwapObject(this, runnerOffset,
null, Thread.currentThread()))
return;
try {
Callable<V> c = callable;
if (c != null && state == NEW) {
V result;
boolean ran;
try {
result = c.call();
ran = true;
} catch (Throwable ex) {
result = null;
ran = false;
setException(ex);
}
if (ran)
set(result);
}
} finally {
// runner must be non-null until state is settled to
// prevent concurrent calls to run()
runner = null;
// state must be re-read after nulling runner to prevent
// leaked interrupts
int s = state;
if (s >= INTERRUPTING)
handlePossibleCancellationInterrupt(s);
}
}
I know the problem somewhere lies in setting up the adapter for listview, i need to update it as i get a new message, but i am unable to get it fixed. Your help would be appreciated

Related Links

Android ListView endless loop both directions
Android Close dataBase Failed
Can't display table in Android
How do I repackaged an AAR for Android gradle manifest merger?
How to pick a value from a TextView into a ListView
ViewPager not displaying correct Image
How to permanently disable Wi-Fi, Bluetooth and USB Mass Storage in Android
CheckBox status save to database Android
How to record audio with Google Glass?
How to get the HTMl page of redirected page using HttpURLConnection with Jsoup
How to set Android Studio path in Worklight Studio on Mac
NullPointerException at OnClickListener in Eclipse
How to update specific field /TextView without affecting other views in Android?
best practice of using lisview with different layout
Sromku facebook login issue
Set app activity to accept action.VIEW action

Categories

HOME
django
xml
grok
porting
powerpoint
yahoo-finance
apiblueprint
jsf-2.2
alarm
google-cloud-functions
x264
jquery-ui-sortable
drop-down-menu
project-intu
why3
cmdb
google-form
renjin
do-while
parameter-passing
mvc-mini-profiler
google-picker
mapstruct
oledb
lilypond
simpleitk
googlebot
springfox
babel
dynamically-generated
moses
android-sharedpreferences
linked-data
angular-translate
twiml
utorrent
weather
cognos-bi
xajax
openalpr
dm-script
p4merge
hackintosh
portforwarding
android-checkbox
httr
ovf
reportservice2010
arules
dt
check-mk
seq
gets
docpad
microstation
dotnetnuke-7
dimension
simevents
sklearn-pandas
ellucian-scribe
atan2
page.js
viola-jones
ocra
entity-framework-4.3
android-cookiemanager
sql-scripts
mdichild
eclipse-kepler
unit-of-work
tlf
kogrid
cnf
wp7test
server-administration
tree-balancing
xcode3.2
veracity
urlrewriter
umra
cuteeditor
facebook-iframe
filesystemobject
silverlight-oob
wordprocessingml
dsoframer
pbcopy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App