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 trialBenjamin Earle
6,204 PointsSuspicious cast to ConnectivityManager
I'm having an error that crashes my app, and it throws this error on eclipse: "Suspicious cast to ConnectivityManager for a CLIPBOARD_SERVICE: expected ClipboardManager"
What should I do??
Error is on the (ConnectivityManager) getSystemService(Context.CLIPBOARD_SERVICE);
part
Here's my code, if it is of any help:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_list);
if(isNetworkAvailable()){
GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();
getBlogPostsTask.execute();
}
else{
Toast.makeText(this, "Network is unavailable!", Toast.LENGTH_LONG).show();
}
//Toast.makeText(this, getString(R.string.no_items), Toast.LENGTH_LONG).show();
}
private boolean isNetworkAvailable() {
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CLIPBOARD_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
boolean isAvailable = false;
if (networkInfo != null && networkInfo.isConnected()){
isAvailable=true;
}
return isAvailable;
}
EDIT: Problem Solved, just an error from my part when typing, typed CLIPBOARD instead of CONNECTIVITY