3

This is my code for posting data to Google Forms. I used OkHTTP3 for sending request.

okhttp3.Request request = new Request.Builder().url(url).post(body).build();

In the above code, it shows cannot resolve symbol Builder.

I have also imported the below packages

import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Response;

and included the below package in the gradle file

compile 'com.squareup.okhttp3:okhttp:3.0.1'
Odomontois
  • 15,918
  • 2
  • 36
  • 71

1 Answers1

4

Replace

okhttp3.Request request = new Request.Builder().url(url).post(body).build();

with

okhttp3.Request request = new okhttp3.Request.Builder().url(url).post(body).build();

It should work.

Saurabh
  • 1,225
  • 9
  • 16
  • Hi, i am trying to implement your answer but all Android Studio 3 prompts me to add is newBuilder(). I tried googling for answers but they only leave me more confused - are Builder() and newBuilder() the same? – kilokahn Nov 13 '17 at 09:56
  • 1
    newBuilder is not static, its accessed via request object. while Builder is a static class and can be accessed directly. – Saurabh Nov 13 '17 at 11:13
  • Got it. I figured out that I have to call Builder by using the full package name as otherwise it defaults to the Request package from Volley, which I was using earlier. Now I say okhttp3.Request.Builder() .... :) – kilokahn Nov 13 '17 at 18:53