Asynctask and Adapter for Listview in conflict

Asked

Viewed 32 times

0

I’m creating a chat app using socket and after developing all the layout I decided to enter the connection part... the problem is that when I receive messages the app closes and presents some errors... I passed in debug and tells me that both my Adapter and my listview are null. I’m new in android and java.

follows a piece of error (line 224 is where adapterMessage.add(message)

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.stevenilson.appchat, PID: 26141
java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:304)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void adapters.MessageAdapter.add(objetos.Message)' on a null object reference
    at com.stevenilson.appchat.TelaDrawer.receive(TelaDrawer.java:224)
    at AsyncTask.TaskConnect.doInBackground(TaskConnect.java:80)
    at AsyncTask.TaskConnect.doInBackground(TaskConnect.java:26)
    at android.os.AsyncTask$2.call(AsyncTask.java:292)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
    at java.lang.Thread.run(Thread.java:818) 

In case you need to see more of the project I have it on Github: https://github.com/LucasGitDev/AppChat

I thank from now on those who can help me.

1 answer

0

Well, your mistake doesn’t seem to be any kind of conflict between Asynctask and Adapter. From what I saw the error happened in the background yes, but because you tried to access a null object, in the case, the Messageadapter is null.

Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void Adapters.MessageAdapter.add(objects.Message)' on a null Object Reference

Make sure you get it started right, maybe that’s the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.