可能有人请解释为什么我得到的错误:Android的网络连接
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;
}
}
感谢非常新的android,我欣赏帮助,投票给你#1 :) – James
@James You非常欢迎!请务必阅读关于清单文件中权限的说明。在设备上访问不同的资源需要在清单文件中设置适当的权限。 – rastating
不要担心在YouTube上观看'thenewboston'和他在Android上的200个视频后, – James