Getting a Unexpected JDWP Error: 103 while trying to upload an image using retrofit to an api server android?
android, android-studio, java, retrofit, retrofit2
Solution
I think your problem is you forgot to add a call adapter to the retrofit object. Within your `RestClient` class you must put something like this:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrlLink)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
Also you need to add this dependency inside `build.gradle`:
compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
I hope it helps.
Cheers.
Problem
I'm getting the following 103 error message while trying to upload an image on the api server using retrofit multipart, the api receives an api token, "_method":"PUT" and image url as parameters, on response receives the complete JSON but with the previous or default image link, the current selected image does not upload, everything else is optional, any help would be appreciated, code is listed below thanks. Also main method is POST but "_method":"PUT" parameter lets you upload the image, without _method it becomes a POST message and every other parameter than becomes compulsory, please check the image. com.sun.jdi.InternalException: Unexpected JDWP Error: 103 Interface: ``` public interface UserSignUpClient { @POST("account") Call<AuthenticationAccountCreationResponse> createAccount(@Body UserSignUp userSignUp); @Multipart @PUT("account") Call<UserInfo> postImage(@Header("Authorization") String headerValue, @PartMap Map<String, String> map, @PartMap Map<String, File> imageMap, @Part MultipartBody.Part image); @FormUrlEncoded @POST("account") Call<UserInfo> updateUser(@Header("Authorization") String headerValue, @FieldMap Map<String, String> map); } ``` Retrofit builder class: ``` public class RestClient { private UserSignInClient userSignInClient; private UserSignUpClient userSignUpClient; private UserInfoClient userInfoClient; public RestClient(String baseUrlLink){ Gson gson = new GsonBuilder() .setLenient() .create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrlLink) .addConverterFactory(GsonConverterFactory.create(gson)).build(); if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_TOKEN)){ userSignInClient = retrofit.create(UserSignInClient.class); } else if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_ACCOUNT_CREATION)) { userSignUpClient = retrofit.create(UserSignUpClient.class); } else if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_USER_INFO)){ userInfoClient = retrofit.create(UserInfoClient.class); } } public UserSignInClient getUserSignInClient() { return userSignInClient; } public UserSignUpClient getUserSignUpClient() { return userSignUpClient; } public UserInfoClient getUserInfoClient() { return userInfoClient; } } ``` Main Class: ``` userImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); galleryIntent.setType("*/*"); startActivityForResult(galleryIntent, RESULT_LOAD_IMG); } }); @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) { Uri selectedImageUri = data.getData(); String filePath = FileUtils.getPath(this, selectedImageUri); file = new File(filePath); image_name = file.getName(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { } else { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } } } } @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { StringBuilder stringBuilder = new StringBuilder(AUTHORIZATION); sharedPreferences = this.getSharedPreferences(getResources().getString(R.string.token), 0); stringBuilder.append(sharedPreferences.getString(getResources().getString(R.string.token), "")); RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file); MultipartBody.Part body = MultipartBody.Part.createFormData("image", file.getName(), requestBody); UserUpdate userUpdate = new UserUpdate(file); methodMap.put("_method","PUT"); imageMap.put("image", file); Call<UserInfo> uploadImage = new RestClient(CONSTS.BASE_URL_ADDRESS_ACCOUNT_CREATION).getUserSignUpClient() .postImage(stringBuilder.toString(), methodMap, imageMap, body); uploadImage.enqueue(new Callback<UserInfo>() { @Override public void onResponse(Call<UserInfo> call, Response<UserInfo> response) { if (response.isSuccessful()) { Picasso.with(DetailActivity.this).load("http://ec2-35-161-195-128.us-west-2.compute.amazonaws.com/" + response.body().getImage()).into(userImage); } } @Override public void onFailure(Call<UserInfo> call, Throwable t) { Toast.makeText(DetailActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show(); } }); } else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } // other 'case' lines to check for other // permissions this app might request } } } return; } // other 'case' lines to check for other // permissions this app might request } } ``` postman api image = https://i.stack.imgur.com/r1BHX.png