Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7173529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:50:36+00:00 2026-05-28T15:50:36+00:00

class Talk { String[] values; try { InputStream is = getAssets().open(jdata.txt); DataInputStream in =

  • 0
class Talk {
        String[] values;
        try {
            InputStream is = getAssets().open("jdata.txt");
            DataInputStream in = new DataInputStream(is);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));

            //Read File Line By Line
            while ((br.readLine()) != null) {
                 // Print the content on the console
                 strLine = strLine + br.readLine();
            }
        } catch (Exception e) { //Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
        parse(strLine);
    }

    public void parse(String jsonLine) {
        Data data = new Gson().fromJson(jsonLine, Data.class);
        values[0]= data.toString();
        return;
    }
}

This is in jdata.txt:

"{" + "'users':'john' + "}"

This is my Data.java:

public class Data {
    public String users;
}

The error I get is:

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 9

Can anyone explain to me what this error means and how to remove it?

EDIT:

I got the answer. These are the tweaks I had to do. First, change the String array to an array list.

List<String> values = new ArrayList<String>();

The next tweak was here:

strLine = currentLine;
              currentLine = br.readLine();
              //Read File Line By Line
              while (currentLine != null)   {
              // Print the content on the console

                  strLine = strLine + currentLine;
                  currentLine = br.readLine();
              }

The final tweak was here:

String val = data.toString();
values.add(val);

Certain parts of the code might be redundant but I will take care of that later.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:50:37+00:00Added an answer on May 28, 2026 at 3:50 pm

    You’re calling readLine() twice. The following causes a line to be read from the file and lost:

    while ((br.readLine()) != null)   {
    

    Change the loop to:

    //Read File Line By Line
    String currentLine = br.readLine();
    while (currentLine != null)   {
         // Print the content on the console
         strLine = strLine + currentLine;
         currentLine = br.readLine();
    }
    

    Also, the contents of jdata.txt should be:

    {"users":"john"}
    

    without superfluous + or " characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the NSObject Class Reference they talk about an isa instance variable which is
class A : IFoo { } ... A[] arrayOfA = new A[10]; if(arrayOfA is
I want a way to pass a string statement from one base class to
How do I get dataanotation to talk to a custom jquery script. public class
I have a class (MiddleMan) talks to a system and this talk is initialized
This is ok: Class<? extends String> stringClass = a.getClass(); But this gets error: <T>
I suppose that a program like this... class Test { public static void main(String[]
I have the following class Item < ActiveRecord::Base end class Talk < Item end
I have a class that does a transformation on a string, like so class
class Foo { static bool Bar(Stream^ stream); }; class FooWrapper { bool Bar(LPCWSTR szUnicodeString)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.