有人可以解释为什么我收到错误:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.project/com.project.Deals}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
当我使用下面的两个类时,已经这样做了很长时间了。我很感激帮助
public class Deals extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview);
NetworkConnection nc = new NetworkConnection();
boolean networkAvail = nc.isNetworkConnAvail();
if (networkAvail == true){
}
}
};
public class NetworkConnection extends Activity {
/** Called when the activity is first created. */
public boolean isNetworkConnAvail() {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null)
return networkInfo.isConnected();
return false;
}
}