Search code examples
javaandroidretrofit2base-url

Caused by: java.lang.IllegalArgumentException: baseUrl must end in /: url


I am using Retrofit2 for API parsing.

I'm using retrofit:2.2.0 and I'm using converter-gson:2.2.0', in the get method, there is an error:

java.lang.IllegalArgumentException: baseUrl must end in /

I have checked my code and there is no problem.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    initViews();
    **loadJSON();**

private void loadJSON(){
    Retrofit retrofit = new Retrofit.Builder()
            **.baseUrl(BASE_URL)**
            .addConverterFactory(GsonConverterFactory.create())
            .build();

Solution

  • You have to add "/" in your BASE URL. eg somesite.com/ or facebook.com/profile/