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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:07:56+00:00 2026-06-09T08:07:56+00:00

I am creating an Online Dictionary Android App. I am using JSON to request

  • 0

I am creating an Online Dictionary Android App.
I am using JSON to request for definitions for a word which the user inputs.
This input is into the variable “text” everytime the search button is clicked.
The Inputted word is then appended into the API request URL which returns the definition……which is stored in variable “result” in the bottom method OnPost Execute()
My TextView should then be set to this String.

I Therefore put the entire JSON and HTTPrequest code within the onClickLIstener because the user input always changes and requests everytime, but im getting an error at the “throws ClientProtocolException” after the “public JSONObject lastTweet(String word)” the error is “Syntax error on tokens, delete these tokens” I am Using Enclipse Indigo.

Here Is my Code:

    public class Dictionary extends Activity {
    String finalresult;
    HttpClient client = new DefaultHttpClient();
    TextView ansa;
    JSONObject json;
    Button Search;
    EditText input; 
    String text;
    final static String URL = "http://api.wordnik.com/v4/word.json/";        
    final static String URL2 = "/definitions?api_key=<MY API KEY>"; 
    String fresult;
    Dictionary dic = new Dictionary();

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dictionary);
        ansa = (TextView) findViewById(R.id.ansa);
        input = (EditText) findViewById(R.id.input);
        Search = (Button) findViewById(R.id.search);

     Search.setOnClickListener(new View.OnClickListener() {


            public void onClick(View v) {
                // TODO Auto-generated method stub
                text = input.getText().toString();

                public JSONObject lastTweet(String word) 
                        throws ClientProtocolException, IOException, JSONException{

                    new Read().execute("text");   
                    StringBuffer strBuff = new StringBuffer();
                     strBuff.append(URL);
                     strBuff.append(word);
                     strBuff.append(URL2);


                    HttpGet get = new HttpGet(strBuff.toString());
                    HttpResponse r = client.execute(get);
                    int status = r.getStatusLine().getStatusCode();
                    if (status == 200){
                        HttpEntity e = r.getEntity();
                        String data = EntityUtils.toString(e);
                        JSONArray timeline = new JSONArray(data);
                        JSONObject last = timeline.getJSONObject(0);
                        return last;

                    }else{
                        Toast.makeText(Dictionary.this, "error", Toast.LENGTH_LONG);
                        return null;

                    }

                }


                class Read extends AsyncTask<String, Integer, String>{

                    @Override
                    public String doInBackground(String... params) {
                        // TODO Auto-generated method stub
                        try {
                            json = lastTweet(text);
                            return json.getString(params[0]);
                        } catch (ClientProtocolException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(String result) {
                        fresult = result;
                        // TODO Auto-generated method stub
                                    }
                }
                    ansa.setText(fresult);
                }

        });

     }  

    public JSONObject lastTweet(String word) 
            throws ClientProtocolException, IOException, JSONException{

        new Read().execute("text");   
        StringBuffer strBuff = new StringBuffer();
         strBuff.append(URL);
         strBuff.append(word);
         strBuff.append(URL2);


        HttpGet get = new HttpGet(strBuff.toString());
        HttpResponse r = client.execute(get);
        int status = r.getStatusLine().getStatusCode();
        if (status == 200){
            HttpEntity e = r.getEntity();
            String data = EntityUtils.toString(e);
            JSONArray timeline = new JSONArray(data);
            JSONObject last = timeline.getJSONObject(0);
            return last;

        }else{
            Toast.makeText(Dictionary.this, "error", Toast.LENGTH_LONG);
            return null;

        }

    }


    class Read extends AsyncTask<String, Integer, String>{

        @Override
        public String doInBackground(String... params) {
            // TODO Auto-generated method stub
            try {
                json = lastTweet(text);
                return json.getString(params[0]);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            fresult = result;
            // TODO Auto-generated method stub
        }
    }

}

Any Suggestions?

  • 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-09T08:07:57+00:00Added an answer on June 9, 2026 at 8:07 am

    Have you tried moving the request code to another class?

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

Sidebar

Related Questions

I'm creating an android app where user loads some data from an online server
i am creating app which would download and save files, than user could use
I'm creating an iPhone app which is going to have an online spreadsheet to
Possible Duplicate: Creating online help in Java Swing application - using pdf user docs
Hi I'm creating online shop. In this shope people online must be buy files
While creating an online shop application using play-1.2.4 ,I ran into some problems with
I just finished creating a large online flex app with 43 different screens. I
I recently tried using the Cloud9 online IDE . It starts by creating a
I am creating an online enrollment form. When a user advances to page 2,
I'm creating an online based system that has public user profiles for all users..

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.