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

  • SEARCH
  • Home
  • 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 8907293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:52:45+00:00 2026-06-15T02:52:45+00:00

I am trying to use the json-lib-2.4-jdk15.json. I don’t have any error in my

  • 0

I am trying to use the json-lib-2.4-jdk15.json. I don’t have any error in my code but when I run my program the catlog :

Caused by: java.lang.NoClassDefFoundError: net.sf.json.JSONSerializer

Whereas I have “import net.sf.json.JSONSerializer;” and eclipse don’t show any error at this line.
I added the .jar like this : Configure Build path -> add external jar .. (so now the jar appear in Referenced Libraries)

My class :

package com.example.androidgridweb;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;

import android.os.AsyncTask;

public class eSearchElastic{



public void ESE (final ImageAdapter imgAdapter)throws ClientProtocolException, IOException {

AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>(){



    @Override
    protected Void doInBackground(Void... params) {
        String server = "servename";
        String index = "images";
        String type = "images_schema_1";
        StringEntity query = null;
        try {
            query = new StringEntity("{\"sort\" : [ {\"confidence_level\" : {\"order\" : \"desc\"} }],\"from\" : 0, \"size\" : 10,\"query\" : {\"text_phrase\" : { \"keyword\" : \"finding nemo\"}},\"filter\" : {\"numeric_range\" : {\"confidence_level\" : { \"from\" : 10, \"to\" : 100, \"include_lower\" : true, \"include_upper\" : true}}}}'");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        int i=0;
        HttpClient httpclient = new DefaultHttpClient();
        StringBuilder urlStr = new StringBuilder("http://");
         urlStr.append(server)
                .append("/" + index)
                .append("/" + type + "/_search");
         System.out.println(urlStr.toString());
         while (i < 5) {
            HttpPost httpost = new HttpPost(urlStr.toString());
            httpost.setEntity((HttpEntity)query);

         httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

             HttpResponse response = null;
            try {
                response = httpclient.execute(httpost);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

             String answer = null;
            try {
                answer = org.apache.http.util.EntityUtils.toString(response.getEntity());
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println(answer);
            i++;

            JSONObject answerJson = (JSONObject) JSONSerializer.toJSON(answer);
            String urlImage;
            try {
                urlImage = answerJson.getString("hits");
                JSONObject answerJson1 = (JSONObject) JSONSerializer.toJSON(urlImage);
                String urlImage1 = answerJson1.getString("hits").replace("[", "").replace("]","");
                JSONObject answerJson2 = (JSONObject) JSONSerializer.toJSON(urlImage1);
                String urlImage2 = answerJson2.getString("_source");
                JSONObject answerJson3 = (JSONObject) JSONSerializer.toJSON(urlImage2);
                String urlImage3 = answerJson3.getString("url");
                System.out.println(urlImage3);
                imgAdapter.addmThumbIds(urlImage3);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

         }
        return null;
    }

};
task.execute();

}

}

Catlog:

FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:278)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:864)
Caused by: java.lang.NoClassDefFoundError: net.sf.json.JSONSerializer
    at com.example.androidgridweb.eSearchElastic$1.doInBackground(eSearchElastic.java:82)
    at com.example.androidgridweb.eSearchElastic$1.doInBackground(eSearchElastic.java:1)
    at   android.os.AsyncTask$2.call(AsyncTask.java:264)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  • 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-06-15T02:52:46+00:00Added an answer on June 15, 2026 at 2:52 am

    Adding the jar to the build path doesn’t mean the jar will be included in the application apk. This is why it works at compile time (eclipse), and it doesn’t at run time.

    Create a “libs” folder at the top level of you android app project, and copy the jar inside that folder. The ADT plugin will automatically add any jar’s in that folder to your eclipse buildpath and to the built apk file.

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

Sidebar

Related Questions

Trying to use a lib but getting this error... npm ERR! JSON.parse Failed to
I am trying to use the JSON-lib api in my code to convert a
I have been trying to use JSON to store settings for a program. I
I am trying to use JSON to populate a div, so I basically run
Trying to use Jbuilder to create some JSON views for my app, but the
I am trying to learn how to use JSON and writing a simple program
Trying to use a query with mongoexport results in an error. But the same
I am trying to use the BrainTree webhooks for subscription transactions but have been
I have been trying to run the rake db:migrate command but it ain't working.
Question: I'm trying to use JSON accross domains, but all i find is JSON

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.