简体   繁体   中英

Error: reached end of file while parsing

I'm currently using Android Studios. I am having trouble compiling my file. I keep getting that error. I searched similar questions but it hasn't helped me.

private void queryBooks(String searchString) {

    // Prepare your search string to be put in a URL
    // It might have reserved characters or something
    String urlString = "";
    try {
        urlString = URLEncoder.encode(searchString, "UTF-8");
    } catch (UnsupportedEncodingException e) {

        // if this fails for some reason, let the user know why
        e.printStackTrace();
        Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
    }

    // Create a client to perform networking
    AsyncHttpClient client = new AsyncHttpClient();

    // Have the client get a JSONArray of data
    // and define how to respond
    client.get(QUERY_URL + urlString,
            new JsonHttpResponseHandler() {

                @Override
                public void onSuccess(JSONObject jsonObject) {
                    // Display a "Toast" message
                    // to announce your success
                    Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();

                    // 8. For now, just log results
                    Log.d("omg android", jsonObject.toString());
                }

                @Override
                public void onFailure(int statusCode, Throwable throwable, JSONObject error) {

                    // Display a "Toast" message
                    // to announce the failure
                    Toast.makeText(getApplicationContext(), "Error: " + statusCode + " " + throwable.getMessage(), Toast.LENGTH_LONG).show();

                    // Log error message
                    // to help solve any problems
                    Log.e("omg android", statusCode + " " + throwable.getMessage());
                }
            }

After debugging my program. I found my answer. I was missing }); before closing my program. Thank you everyone for helping me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM