logo
down
shadow

org.json.JSONException: End of input at character 0 of


org.json.JSONException: End of input at character 0 of

By : Fd4all234
Date : November 22 2020, 10:54 AM
will be helpful for those in need I am trying to upload video to server,but whenever I am trying to upload response is showing null null and in logcat it shows org.json.JSONException: End of input at character 0 of,instead of my response status:success msg:video uploaded..can any body tell me what is my mistake? , Try to use BufferedReader :
code :
BufferedReader r = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder result = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
    result.append(line);
}


Share : facebook icon twitter icon
org.json.JSONException: End of input at character

org.json.JSONException: End of input at character


By : wad_ad
Date : March 29 2020, 07:55 AM
To fix the issue you can do when I try to get json that doesn't have object, it works fine. but when I try go get json that has an object it's getting error. , Change
code :
 JSONObject jsonObject = new JSONObject(result);
result=getJSONUrl(url);  //<< get json string from server
JSONObject jsonObject = new JSONObject(result);
org.json.JSONException: End of input at character 0

org.json.JSONException: End of input at character 0


By : user2214930
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have been stuck on this for a while. Simply cannot figure out whats wrong. A pair of fresh eyes would be very helpful. I keep on getting the org.json.JSONException: End of input at character 0 of and cannot figure it out. ,
org.json.JSONException: End of input at character 0
code :
<?php

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['driver'], $_POST['licencenum'], $_POST['officer'], $_POST['speed'] , $_POST['fine'],$_POST['category'])){

    $driver = $_POST['driver'];
    $licencenum = $_POST['licencenum'];
    $officer = $_POST['officer'];
    $speed = $_POST['speed'];
    $fine = $_POST['fine'];
    $category = $_POST['category'];


    // include db connect class
    require_once __DIR__ . '/db_connect.php';

    // connecting to db
    $db = new DB_CONNECT();

    // mysql inserting a new row
    $result = mysql_query("INSERT INTO fineregister(driver,licencenum,officer,speed,fine,category) VALUES   ('$driver','$licencenum','$officer','$speed','$fine','$category')");

    // check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = true;
        $response["message"] = "Speed Ticket Successfully Registered.";
        // echoing JSON response
    } else {
        // failed to insert row
        $response["success"] = false;
        $response["message"] = "Oops! An error occurred.";
    }
} else {
    // required field is missing
    $response["success"] = false;
    $response["message"] = "Required field(s) is missing";
}
    // echoing JSON response
    echo json_encode($response);
?>
public String makeHttpRequest(String url, List<NameValuePair> params) 
{
    InputStream is = null;
    String json = "";

    // Making HTTP request
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();


    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();

        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }


    // return JSON String
    return json;

}
protected String doInBackground(String... args) {
    String driver = inputDriver.getText().toString();
    String licencenum = inputLicence.getText().toString();
    String officer = inputOfficer.getText().toString();
    String speed = inputSpeed.getText().toString();
    String fine= FineAppl.getText().toString();
    String category = inputCategory.getText().toString();


    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("driver", driver));
    params.add(new BasicNameValuePair("licencenum", licencenum));
    params.add(new BasicNameValuePair("officer", officer));
    params.add(new BasicNameValuePair("speed", speed));
    params.add(new BasicNameValuePair("fine", fine));
    params.add(new BasicNameValuePair("category", category));

    // getting JSON String
    // Note that create product url accepts POST method
    String json = jsonParser.makeHttpRequest(url_create_fine, params);

    return json;
}



protected void onPostExecute(String json) {
    // dismiss the dialog once done
    pDialog.dismiss();
    Log.d("mylog", "json = " + json);
    //parse here
}
try {
    JSONObject jsonData = new JSONObject(json);
    Boolean success = jsonData.getBoolean("success");
    String message = jsonData.getString("message");

    if (success) {
    //success
    } else {
    // failed to Register Fine
    }
} catch (JSONException e) {
    e.printStackTrace();
}
org.json.JSONException: End of input at character 0 of

org.json.JSONException: End of input at character 0 of


By : Gerardo Tezza
Date : March 29 2020, 07:55 AM
this one helps. Answer : Response object should of Generic type - ResponseBody.
See below Correct code for reference.
code :
ResponseBody rb = response.body(); 
rb.string();
@Override
public void onResponse(Call call, Response<ResponseBody> response) throws IOException {
   if (response.isSuccessful()) {

      String remoteResponse=response.body().string();
      Log.d(TAG, remoteResponse);
      try {
          JSONObject forecast = new JSONObject(remoteResponse);
      } catch (JSONException e) { 
          e.printStackTrace();
      }
   }
}
org.json.JSONException: End of input at character 0 of

org.json.JSONException: End of input at character 0 of


By : Paul Fabrie
Date : March 29 2020, 07:55 AM
wish helps you Based on the error, you aren't getting JSON back, which likely means you are getting some HTTP error.
You could more easily see that if you Log the value of result before trying to parse it.
code :
String API_KEY = "XXXXxxxx";
String url = "http://.../weather?q=" + city + "&APPID=" + API_KEY;
org.json.JSONException: End of input at character XYZ

org.json.JSONException: End of input at character XYZ


By : Yaum Verma
Date : March 29 2020, 07:55 AM
This might help you
in this stackover issue org.json.JSONException: End of input at character somebody wrote that the solution is this
code :
    Response.Listener<String> responseListener = new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                Log.d("response", "Size: "+response.length());
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org