Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialpranav kakkad
755 PointsOkHttpClient is showing error
Whenever I declare OkHttpClient it shows error i have already added dependency in gradle file.
This is my Main activitys code:
package com.example.*.stormy;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String apiKey="2dc77c575a5fa74482a9c5a9fbb5ad0d";
double latitude=37.8267,longitude=-122.4233;
String forecastUrl="https://api.darksky.net/forecast/"+ apiKey+"/"+latitude+","+longitude;
OkHttpCLient client=new OkHttpCLient();
}
}
and my dependency code is :
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.1' testCompile 'junit:junit:4.12' compile 'com.squareup.okhttp3:okhttp:3.0.1' }
1 Answer
Jasmeet Singh
20,145 Points@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String apiKey="2dc77c575a5fa74482a9c5a9fbb5ad0d";
double latitude=37.8267,longitude=-122.4233;
String forecastUrl="https://api.darksky.net/forecast/"+ apiKey+"/"+latitude+","+longitude;
OkHttpCLient client=new OkHttpCLient(); <-------- OkHttpClient client=new OkHttpClient();
}
It's probably a typo error.
Other than that make sure you didn't added the mockserver denpendency. The correct dependency is compile 'com.squareup.okhttp3:okhttp:3.6.0'