question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fraction type JSONObject Parsing Error

See original GitHub issue

Describe the bug Fraction’s rule type HasIntegerPartEqualTo is not parsing correctly.

To Reproduce Steps to reproduce the behavior:

  1. Go to Chapter 6 - Mixed Numbers and the Number line (Alpha Data only)
  2. Nothing will show on screen

Expected behavior The data should be parsed correctly.

Demonstration

Environment

  • Device/emulator being used: emulator
  • Android or SDK version (e.g. Android 5 or SDK 21): SDK 28
  • App version (you can get this through system app settings or via the admin controls menu in-app): 1 with data from the assets repository

Additional context Error Log

/org.oppia.android E/StateFragment: Failed to retrieve ephemeral state
    org.json.JSONException: Value 0 at x of type java.lang.Integer cannot be converted to JSONObject
        at org.json.JSON.typeMismatch(JSON.java:101)
        at org.json.JSONObject.getJSONObject(JSONObject.java:616)
        at org.oppia.android.domain.util.StateRetriever.createExactInputForFractionInput(StateRetriever.kt:330)
        at org.oppia.android.domain.util.StateRetriever.createExactInputFromJson(StateRetriever.kt:301)
        at org.oppia.android.domain.util.StateRetriever.convertToRuleSpec(StateRetriever.kt:263)
        at org.oppia.android.domain.util.StateRetriever.createSingleAnswerGroupFromJson(StateRetriever.kt:126)
        at org.oppia.android.domain.util.StateRetriever.createAnswerGroupsFromJson(StateRetriever.kt:94)
        at org.oppia.android.domain.util.StateRetriever.createInteractionFromJson(StateRetriever.kt:67)
        at org.oppia.android.domain.util.StateRetriever.createStateFromJson(StateRetriever.kt:49)
        at org.oppia.android.domain.exploration.ExplorationRetriever.createStatesFromJsonObject(ExplorationRetriever.kt:58)
        at org.oppia.android.domain.exploration.ExplorationRetriever.loadExplorationFromAsset(ExplorationRetriever.kt:46)
        at org.oppia.android.domain.exploration.ExplorationRetriever.loadExploration(ExplorationRetriever.kt:33)
        at org.oppia.android.domain.exploration.ExplorationProgressController.retrieveCurrentStateWithinCacheAsync(ExplorationProgressController.kt:463)
        at org.oppia.android.domain.exploration.ExplorationProgressController.retrieveCurrentStateAsync(ExplorationProgressController.kt:446)
        at org.oppia.android.domain.exploration.ExplorationProgressController$getCurrentState$1.invokeSuspend(ExplorationProgressController.kt:438)
        at org.oppia.android.domain.exploration.ExplorationProgressController$getCurrentState$1.invoke(Unknown Source:10)
        at org.oppia.android.util.data.AsyncResult$transformAsync$2.invokeSuspend(AsyncResult.kt:90)
        at org.oppia.android.util.data.AsyncResult$transformAsync$2.invoke(Unknown Source:10)
        at org.oppia.android.util.data.AsyncResult.transformWithResultAsync(AsyncResult.kt:147)
        at org.oppia.android.util.data.AsyncResult.transformAsync(AsyncResult.kt:89)
        at org.oppia.android.util.data.DataProviders$Companion$transformAsync$1.retrieveData(DataProviders.kt:73)
        at org.oppia.android.util.data.DataProviders$NotifiableAsyncLiveData.retrieveFromDataProvider(DataProviders.kt:364)
        at org.oppia.android.util.data.DataProviders$NotifiableAsyncLiveData.handleDataProviderUpdate(DataProviders.kt:352)
        at org.oppia.android.util.data.DataProviders$NotifiableAsyncLiveData$onActive$job$1.invokeSuspend(DataProviders.kt:311)

Data

"rule_specs": [{
"rule_type": "HasIntegerPartEqualTo",
"inputs": {
  "x": 0
}
}, {
"rule_type": "HasIntegerPartEqualTo",
"inputs": {
  "x": 1
}
}, {
"rule_type": "HasIntegerPartEqualTo",
"inputs": {
  "x": 2
}
}],

To Fix

  1. Open file oppia-android/domain/src/main/assets/test_exp_id_2.json
  2. Go to line 407 - https://github.com/oppia/oppia-android/blob/88f25ec53337dadbbf5c73db537257cc8c7484a6/domain/src/main/assets/test_exp_id_2.json#L407
  3. Add 1 more rule type
{
   "rule_type": "HasIntegerPartEqualTo",
        "inputs": {
            "x": 1
         }
 }

it will look like this after adding

"rule_specs": [{
              "rule_type": "IsExactlyEqualTo",
              "inputs": {
                "f": {
                  "isNegative": false,
                  "wholeNumber": 0,
                  "numerator": 1,
                  "denominator": 2
                }
              }
            },
              {
                "rule_type": "HasIntegerPartEqualTo",
                "inputs": {
                  "x": 1
                }
              }],
  1. Uninstall the already installed oppia app if there is any on your testing device
  2. Install app and open First Test Topic
  3. Nothing will be shown on screen and error will occur on logcat.
  4. Now, add the logic to parse new rule - https://github.com/oppia/oppia-android/issues/4202#issuecomment-1042790267
  5. re-install the app and open First Test Topic, it will work fine now.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
anandwana001commented, Mar 8, 2022

@adizcode Chapter 6 mentioned in the issue is a part of the alpha production app so the data can’t be shared. I had added the steps in PR description.

1reaction
BenHenningcommented, Feb 18, 2022

This seems reasonable to add, though FWIW this won’t affect alpha since we don’t use the JSON loader for those lessons.

De-assigning and marking as a good first issue for someone to pick up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Value connection of type java.lang.String cannot be converted ...
Error:Json parsing error: Value connection of type java.lang.String cannot be converted to JSONObject ... php include ('config.php'); $id = ...
Read more >
SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
SyntaxError: JSON.parse: bad parsing Breaking Your Code ...
The JSON Parse error, as the name implies, surfaces when using the JSON. parse() method that fails to pass valid JSON as an...
Read more >
JSONObject - Android Developers
Errors. ServiceConfigurationError. java.util.concurrent ... Throws. JSONException, if the parse fails or doesn't yield a JSONObject .
Read more >
SyntaxError: JSON.parse: bad parsing - LambdaTest
Nearly all JSON.parse errors are a subset of SyntaxError error type. Debugging console throws around 32 different errors messages when you mess ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found