Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

albara khaled
5,013 PointsGetting the NoClassDefFoundError error!
Please help me to solve this issue, I tried many ways and it didn't work :(

albara khaled
5,013 Pointspackage abdulrahman.com.stormy;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class MainActivity extends AppCompatActivity {
public static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String apiKey = "***";
double latitude = 37;
double longitude = -122;
String forecastUrl = "https://api.forecast.io/forecast/"+apiKey+"/"+latitude+","+longitude;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(forecastUrl)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
Log.v(TAG, response.body().string());
if (response.isSuccessful()) {
}
else {
alertUserAboutError();
}
} catch (IOException e) {
Log.e(TAG, "Exception caught: ", e);
}
}
});
Log.d(TAG, "Main UI code is runing!");
}
private void alertUserAboutError() {
AlertDialogFragment dialog = new AlertDialogFragment();
dialog.show(getFragmentManager(), "error");
}
}
//and this is the class
public class AlertDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle("Oops!")
.setMessage("Error!")
.setPositiveButton("Sorry!",null);
AlertDialog dialog = builder.create();
return dialog;
}
}

albara khaled
5,013 Pointsnotice that I'v change the variable values String apiKey = "***"; double latitude = 37; double longitude = -122; it's not real.
one friend told me that issue is in the library!
3 Answers

jcorum
71,814 PointsWhen I test your query string: https://api.forecast.io/forecast/***/32,-122
I get a 400 Bad Request. So it looks like your friend may be right.

albara khaled
5,013 Pointssir, please try this link : https://api.forecast.io/forecast/bd0b75bbdd785c256cd8494010199985/37.8267,-122.423

albara khaled
5,013 Points//or
String apiKey = "bd0b75bbdd785c256cd8494010199985";
double latitude = 37.8267;
double longitude = -122.423;
String forecastUrl = "https://api.forecast.io/forecast/"+apiKey+"/"+latitude+","+longitude;

jcorum
71,814 PointsI did, and it works. You can try it too. Just copy it and paste it into the address bar of any browser.

albara khaled
5,013 PointsI know link is working, but AS is not
jcorum
71,814 Pointsjcorum
71,814 PointsCan you be a bit more specific? It's hard to guess at which point in the video you did something that generated the above error. It helps even more if you can paste in the code you were changing when you got the error!