I try to upload a video to the server, but whenever I try to upload a response, null null is displayed, and org.json.JSONException is displayed in logcat: End of input with character 0 of, instead of my response status: success msg: video uploaded .. can someone tell me what is my mistake? 
public class VideoUpload extends Activity{ MediaController mc; private static int SELECT_PICTURE = 1; private String selectedImagePath=""; TextView messageText; Button uploadButton; int serverResponseCode = 0; ProgressDialog dialog = null; private static final String TAG_SUCCESS = "status"; private static final String TAG_MSG = "msg"; String imgs; String btns; String upLoadServerUri = null; ThreadPolicy th = new ThreadPolicy.Builder().permitAll().build(); final String uploadFilePath = Environment.getExternalStorageDirectory().getPath(); private Button buttonLoadImage; private VideoView img; private String User_ID; private String sta; private String msg; private HttpURLConnection conn = null; private String result=""; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_video); StrictMode.setThreadPolicy(th); User_ID=this.getIntent().getStringExtra("id"); System.out.println("photo upload user id"+User_ID); img = (VideoView)findViewById(R.id.imgViewvid); mc = new MediaController(this); mc.setAnchorView(img); buttonLoadImage = (Button) findViewById(R.id.buttonLoadvid); buttonLoadImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(); intent.setType("video/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE); } }); uploadButton = (Button)findViewById(R.id.uploadButtonvid); messageText = (TextView)findViewById(R.id.messageTextvid); uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog = ProgressDialog.show(VideoUpload.this, "", "Uploading file...", true); new Thread(new Runnable() { public void run() { runOnUiThread(new Runnable() { public void run() { messageText.setText("uploading started....."); } }); uploadFile(selectedImagePath); } }).start(); } }); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE) { Uri mVideoURI = data.getData(); selectedImagePath = getPath(mVideoURI); messageText.setText(selectedImagePath); System.out.println(requestCode); System.out.println("Image Path : " + selectedImagePath); img.setVideoURI(mVideoURI); } } } @SuppressWarnings("deprecation") public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } public int uploadFile(String sourceFileUri) { DataOutputStream dos = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; File sourceFile = new File(sourceFileUri); if (!sourceFile.isFile()) { dialog.dismiss(); Log.e("uploadFile", "Source File not exist :" + selectedImagePath); runOnUiThread(new Runnable() { public void run() { messageText.setText("Source File not exist :" + selectedImagePath); } }); return 0; } else { try { btns=uploadButton.getTag().toString(); System.out.println(btns); String fileName = sourceFileUri; File f = new File(selectedImagePath); imgs= f.getName(); System.out.println(imgs); upLoadServerUri = "http://mywebsitename.com/webservice/addvideo?version=apps&user_login_id="+User_ID+"&video_1="+imgs+"&action="+btns; FileInputStream fileInputStream = new FileInputStream(sourceFile); URL url = new URL(upLoadServerUri); System.out.println(url); conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true);
source share