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

common runonUIthread for whole application
how to Fused location Run in Background service continuously
React-Native Twitter login for Android
How to dismiss progress bar once otp read from Inbox in android?
Idling resource exits even when isIdleNow() returns false in espresso
When adding Facebook SDK “ appeventslogger.activateapp(this)” is shown deprecated
Android marshmallow WifiManager leaking IntentReceiver
Adding ffmpeg OMX codec to Genymotion Android 4.4.2 emulator
Separate each rom listview android [closed]
Capturing a photo taken from a gallery intent
Android - Best approach for passing context in adapter (Specifically `RecyclerViewAdapter`)
Understanding Android Binders
android app is not visible in the play store after I pushed it to Open Beta
How to dynamically add preferences into preferences screen and bind their values?
Realm.io irrational big data usage on android
Is event bus library mechanism as bad as the use of static variables to pass data between activities?

Categories

HOME
batch-file
twitter-bootstrap-3
checkstyle
fuelux
time-complexity
ng-idle
swt
access
seo
cublas
carousel
rom
permissions
cq5
pyqt4
gembox-spreadsheet
p2p
reactive-programming
jxl
jsonpath
scrolltop
dynamic-sql
standards
windows-xp
rubymotion
blade
resourcebundle
comparator
dynamically-generated
syntax-highlighting
has-and-belongs-to-many
card.io
hreflang
activexobject
nested-lists
parse-tree
css-position
linq-to-objects
berkeley-db-je
clang++
optimizely
x++
mesosphere
builder
vugen
pybrain
rocks
flex-monkey
winusb
flex4.6
burrows-wheeler-transform
jquery-jscrollpane
dimension
xdoclet
jclouds
clipboard.js
upx
qt5.2
dllimport
poppler
android-launcher
typeconverter
zxspectrum
shopizer
umlgraph
device-tree
encryption-asymmetric
template-deduction
twitter-bootstrap-rails
xmltodict
high-resolution
artemis
kendo-dataviz
ebay-lms
modular
script#
kogrid
mvc-editor-templates
cnf
cmmi
composite-component
alice
patricia-trie
pstack
iboutlet
azman
urlrewriter
saxparseexception
update-statement
metaweblog
globals
lxr
java1.4

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