Issue
I am using OkHttp library to multipart data and everything is good i don't have any error but when i compile the program then it gives me error
Error:(172, 40) error: cannot access ByteString class file for okio.ByteString not found
The error occurs here RequestBody.create(MEDIA_TYPE_JPG, new File(data.getFileParam())))
Here is the whole code of method that implements multipart request
public static String makeRequest(RequestConstructor data, String a, String b) {
final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
try {
OkHttpClient client = new OkHttpClient();
Log.d("test",data.getFileParam());
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("bunting", data.getParam("bunting"))
.addFormDataPart("dangler", data.getParam("dangler"))
.addFormDataPart("poster", data.getParam("poster"))
.addFormDataPart("tearPad", data.getParam("tearPad"))
.addFormDataPart("leafLet", data.getParam("leafLet"))
.addFormDataPart("outlet_category", "")
.addFormDataPart("dealerName", data.getParam("dealerName"))
.addFormDataPart("brouchers", data.getParam("brouchers"))
.addFormDataPart("wobblers", data.getParam("wobblers"))
.addFormDataPart("tentCard", data.getParam("tentCard"))
.addFormDataPart("others", data.getParam("others"))
.addFormDataPart("photo", "1.jpg",
RequestBody.create(MEDIA_TYPE_JPG, new File(data.getFileParam())))
.build();
Request request = new Request.Builder()
.url(data.getUrl())
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
Log.d("From OkHTTP Response", response.toString());
System.out.println(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
I don't have any import for okio class so i tried to add manully fun android studio show syntax error cannot resolve symbol okio
Solution
It's a separate package we need to include by our self. Name is: Okio.
You can find the latest jar or java file here: https://github.com/square/okio
Answered By - Jakir Hossain
Answer Checked By - Terry (JavaFixing Volunteer)