在这里,基本上我所做的就是检查连接是否可用。如果连接不可用,我将重定向到另一个活动。就是这样。但它一直在崩溃。
Intent i;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
i = new Intent(Jsouptesting3Activity.this, NoInternet.class);
Jsouptesting3Activity ob1=new Jsouptesting3Activity();
ob1.isDataConnectionAvailable(this);
try {
doc = Jsoup.connect("http://www.way2franchise.com/").get();
//System.out.println(doc);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("cant connect");
e.printStackTrace();
public void isDataConnectionAvailable(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if(info == null)
{
System.out.println("No net bob");
i = new Intent(Jsouptesting3Activity.this, NoInternet.class);
startActivity(i);
}
System.out.println("YES net bob");
当程序执行时,我正在调用 isDataConnectionAvailable()
并且我没有可用的连接。因此根据逻辑它必须被重定向并且应该打开 NoInternet 活动。
我错过了什么严重的事情吗?
请帮忙。
logcat 堆栈
Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1659
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1675
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 121
ActivityThread$H.handleMessage(Message) line: 943
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 130
ActivityThread.main(String[]) line: 3701
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 866
ZygoteInit.main(String[]) line: 624
NativeStart.main(String[]) line: not available [native method]