0

I'm getting this simple json response and I can't access the value easily. The response is this

{"email":"[email protected]"}

That's after doing json.toString(). Now I'm trying to access the value of email and I keep getting errors. I thought it was just

json.getString("email")

Also this is in java.

edit: here are the errors I'm getting

07-22 06:45:11.524: E/AndroidRuntime(9977): FATAL EXCEPTION: AsyncTask #2
07-22 06:45:11.524: E/AndroidRuntime(9977): java.lang.RuntimeException: An error occured while executing doInBackground()
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.lang.Thread.run(Thread.java:856)
07-22 06:45:11.524: E/AndroidRuntime(9977): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4609)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:867)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:4066)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.view.View.invalidate(View.java:10193)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.invalidateRegion(TextView.java:4375)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.invalidateCursor(TextView.java:4318)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.spanChange(TextView.java:7172)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:8759)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:979)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:688)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.Selection.setSelection(Selection.java:76)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.Selection.setSelection(Selection.java:87)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:302)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.setText(TextView.java:3535)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.setText(TextView.java:3405)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.EditText.setText(EditText.java:80)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.widget.TextView.setText(TextView.java:3380)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at com.reflap.reflap.EditProfile$fillfields.doInBackground(EditProfile.java:61)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at com.reflap.reflap.EditProfile$fillfields.doInBackground(EditProfile.java:1)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-22 06:45:11.524: E/AndroidRuntime(9977):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-22 06:45:11.524: E/AndroidRuntime(9977):     ... 5 more

I'm doing this in a background process.

5
  • what errors you are getting? Commented Jul 22, 2013 at 10:42
  • I suggest you post your whole code for deserializing the json, as well as the json text itelf (unless it really only consists in {"email":"[email protected]"}). Also if you have any stack trace, that would help. Commented Jul 22, 2013 at 10:42
  • The json text is just {"email":"[email protected]"} That's it. Commented Jul 22, 2013 at 10:44
  • have you did this JSONObject object = new JSONObject(" {"email":"[email protected]"} "); before doing json.getString("email")? Commented Jul 22, 2013 at 10:46
  • 3
    It has nothing to do with te parsing of the json but that you are trying to manipulate a textview in a background thread. Do that in onPostExecute instead. Commented Jul 22, 2013 at 10:51

1 Answer 1

2

I believe your stack trace is not caused by the parsing of the JSON data, but by the fact your AsyncTask is referencing the UI (some TextView) in the doInBackground method.

You would normally reference your views onPostExecute, possibly through WeakReference s.

Sign up to request clarification or add additional context in comments.

1 Comment

ahh yeah, that might be it. Just a sec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.