You should invoke your async task with execute()
and not by directly calling the doInBackground()
method on it in the UI thread, as evidenced by the stacktrace:
at artha.ordermaking.KOT.library.JSONParser.doInBackground(JSONParser.java:36)
at artha.ordermaking.KOT.library.UserFunctions.loginUser(UserFunctions.java:37)
From comments:
jsonObject=jsonParser.execute(); Its not working. I need to get JSONObject. execute() is returning AsyncTask Object.
That would not be an async task if you waited for its completion.
Instead, do all processing in doInBackground()
and update your UI in onPostExecute()
which has access to the doInBackground()
result. This update can also involve calling a callback method in your UI code.
In your updated question:
jsonObject= jsonParser.execute("").get();
get()
is the wrong solution. It blocks the current thread (UI thread) until the async task completes. So you're back where you started from: preventing a network operation to block the UI thread.