Struggling with parsing JSON data into a TextView resulting in app crashes

After completing the input, the app crashes without executing any further actions.

I have modified the code to display only the UPC and Product information instead of the entire section. Any suggestions on how to fix this issue?

If there is a similar question already answered somewhere, please provide a link for reference.

Error Logs:

A series of crash logs showing a NullPointerException in the networking code.

The Networking class in the net.example.glutefree package requires some updates to fix an issue regarding handling views in a separate thread.

XML layout file snippet:

The XML layout file contains TextView elements to display the fetched data.

New Error Details:

An error message indicating that the view hierarchy should only be accessed by the main thread and not from a background thread.

Answer №1

After reviewing your logs, it appears that there is a NullPointerException on line 113:

TextView upca = (TextView)findViewById(R.id.textView1); //line 112
upca.setText("UPCA: " + UPCA); //line 113

This error indicates that the upca TextView is not properly initialized in line 112. Please verify if you have included a textView1 in the layout specified above.

Update: Another error you are encountering is

ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

This issue arises when attempting to update the UI Thread from a different Thread. In the code, you are calling getServerData() from a new Thread, but then trying to modify the text of the TextViews belonging to the UI Thread within the method.

Does this explanation help clarify the situation?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The initial row's Id will be used as the Id for all subsequent rows within a JSON object

After dragging a tr in a table and confirming by clicking a button, I need the order list to be updated in the database. To achieve this, I created a JSON object where I intend to save the ids and their corresponding new orders. The issue I am facing is t ...

Navigating forward slashes in JSON within a Java/Spring application: tips and tricks

In my application, I have a function that efficiently parses JSON data received through Postman and uses the GSON library to populate an object. The object is then returned as JSON to the user. However, there is one issue with this process - one of the va ...

Guide on converting XML and JSON data in Swift 3

As a newcomer to IOS, I am looking to convert some mixed data (combination of XML and JSON) received from a SOAP web service into an array using Swift 3. This data is being received as a string variable in the parser method. func connection(_ connection: ...

Converting a JSON array into a Java map

I am currently working on a project that involves receiving a JSON response from my API using entities and DTO. Here is an example of the response structure: return XXXResponseDTO .builder() .codeTypeList(commonCodeDetailL ...

receiving an undefined value from a remote JSON object in Node.js

I have been struggling to extract the specific contents of a JSON api without success. Despite my best efforts, the console always returns undefined. My goal is to retrieve and display only the Question object from the JSON data. After spending several h ...

Converting basic text into JSON using Node.js

Today I am trying to convert a text into JSON data. For example: 1 kokoa#0368's Discord Profile Avatar kokoa#0000 826 2 Azzky 陈东晓#7475's Discord Profile Avatar Azzky 陈东晓#0000 703 3 StarKleey 帅哥#6163's Di ...

Dealing with Array Problem in iOS Swift 3 when converting Object to JSON

public class LessonAssignment { private var title : String? private var category : String? private var week : Int? private var day : Int? //Title public func getTitle() -> String { return title! } public func ...

Learn how to pull values from a single JsonNode into multiple beans within a Play Framework controller

In my Java project using Play Framework, I am working with jQuery Ajax to post data in the form of a String representation of JsonNode. When writing an action method in my controller class to handle this Ajax call, I encountered an issue. The data being s ...

Converting <br to JSON parsing in Android may present challenges and errors, such as "<br cannot be

Here is the JSON data that I need to parse: {"result":[{"emailfrom":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="354675461b565a58">[email protected]</a>"}]} I am attempting to parse it in the following manner: ...

Troubleshooting JavaScript Date Problem with Internet Explorer 7

When I retrieve a Date from a web method, it comes in the format of "Mon Sep 30 07:26:14 EDT 2013". However, when I try to format this date in my JavaScript code like this: var d= SomeDate.format("MM/dd/yyyy hh:mm:ss tt"); //Somedate is coming from the we ...

Utilizing the $skip parameter in the SharePoint 2013 RESTful API

Excuse my lack of experience with REST, as I am new to it. Currently, I am utilizing SP2013 Odata (_api/web/lists/getbytitle('<list_name>')/items?) in order to retrieve the contents of a list. This particular list contains 199 items, so I ...

How to Transform JSON Element into a JavaScript Array in AngularJS?

Implementing AngularJS to fetch values in JSON format using $resource call. The model element I require is a Javascript array structured as: [ [1328983200000, 40], [1328983200000, 33], [1328983200000, 25], [1328983200000, 54], [1328983200000, 26], [1328 ...

Guide on how to send JSON data embedded within an object using Spring Boot

Within my Spring Boot controller, I have an endpoint that retrieves data in a complex structure: public ResponseEntity<Map<String, Map<String, Object>>> getComplexStructure() The inner Object within this structure is stored as raw JSON s ...

Browsing through an array of objects in PHP

Currently working on creating an array of objects using jQuery. var selected_tests = $("#selected_tests").find("tr"); jsonLab = []; $.each(selected_tests, function() { jsonLab.push({ test: ($(this).children()).eq(0).text(), amount: ($(this).chil ...

Built-in JSON parser in Java

I've recently encountered a task that involves making a request and extracting the value of a specific key from JSON data. Due to some constraints, I am required to only utilize built-in Java libraries for this purpose. While I have successfully impl ...

Java Regular Expression not replacing all instances in certain JSON object (converted to a string)

Having trouble removing all the slashes from a JSON Object and adding it to an array list. No matter what Regex I use, I can't seem to get rid of the slashes or the brackets and duplicate strings. It's been a struggle trying different things, eve ...

Attempting to utilize MarkLogic's JSON XQuery functionality for querying purposes is unfortunately not successful

After loading Twitter's JSON search output into Marklogic and transforming it into Marklogic's JSON XML format using the basic transformer, I encountered an issue when trying to query for the id. The XQuery snippet used for querying is as follow ...

What specifically makes this JSON invalid?

Validation of the JSON below is failing, with the first string value from "Can an officer... causing issues according to the validator. It seems like a legitimate start for a string value associated with the key. What could be causing this problem? { ...

The functionality of Laravel's IlluminateHttpJsonResponse::json method is not available in every situation, as it is only applicable in certain

In my application, there is a controller method that interacts with an external API and returns the result. The flow of this controller method is as follows: ControllerY -> getDataFromExternalAPI() This controller method gets called in two different wa ...

Saving data to a database using knockout.js and JSON objects: A step-by-step guide

I have been assigned a task to work with knockout.js. In my project, I have a model called "employee" with fields such as name, country, and state. However, the issue I am facing is that I am unable to save any changes made during the editing process. Her ...