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 6909441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:41:22+00:00 2026-05-27T08:41:22+00:00

Eclipse always gives me this compilation error when I try to get the length

  • 0

Eclipse always gives me this compilation error when I try to get the length of a JSONArray:

the method length() is undefined for the type JSONArray

Here is the code:

import org.springframework.context.annotation.Scope;
import java.net.*;
import java.io.*;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import javax.inject.Named;

@Named("search")
@Scope("request")

public class Search {

    private String query;
    private String result;
    private int num;


    public String getQuery() {
        return query;
      }
    public void setQuery(String query) {
        this.query = query;
      }
    public String getResult() {
        return this.result;
      }
    public void setResult(String result) {
        this.result = result;
      }
    public int getNum() {
        return this.num;
      }
    public void setNum(int num) {
        this.num = num;
      }


    public String send() {
         try 
        {
            //SEND REQUEST TO SOLR SERVER

            URL url = new URL("http://localhost:8983/solr/select/?q="+this.query +"&version=2.2&start=0&rows=100&indent=on&wt=json");

            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;

            while ((str = in.readLine()) != null) 
            {
                this.result = this.result+str;
            }

            in.close();

            //CONVERT RESULT TO OBJECT


           this.result=this.result.substring(4);
           JSONObject json = (JSONObject) JSONSerializer.toJSON(this.result);
           JSONArray results = new JSONArray();
            json = json.getJSONObject("response");
            this.num = json.getInt("numFound");

            results = json.getJSONArray("docs");
            int num = results.length();

I have no idea why this error is popping up. How is this caused and how can I solve it?

  • 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-27T08:41:23+00:00Added an answer on May 27, 2026 at 8:41 am

    The javadoc here doesn’t show a length() method for JSONArray. Hence the error. It does have size() though, is that what you’re after?

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

Sidebar

Related Questions

When I try to use HaskellFP for Eclipse, I always get a popup that
If I type a method name that does not exist, Eclipse always offers me
I try to use @Valid annotation, but eclipse always gives the Valid cannot be
**In any javaProject in eclipse there we always get .classpath file...like <?xml version=1.0 encoding=UTF-8?>
I get a MediaException (Prefetch error: -5) when executing the following code on a
I am stuck in strange error in my eclipse, in which content assist always
This does not always happen, but sometimes when I try to build a (large)
I find that the Eclipse XML editor always inserts tabs for spaces even if
I've always found the eclipse's automatic close quotes and parenthesis features to be useless.
At present I am using eclipse for JAVA project. I always wanted to use

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.