Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:47:01+00:00 2026-05-24T04:47:01+00:00

package info.testing; import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import android.app.Activity; import android.os.Bundle;

  • 0
package info.testing;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;

public class SoupActivity extends Activity {

private static final String TAG = "SoupActivity";
private static final String DATA = null;
private String data = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    if(savedInstanceState != null)
    {
        data = savedInstanceState.getString(DATA);
        showResults();
    }
    else
    {
        parsePage();
    }
}

protected void parsePage(){
    Document doc = null;
    try {
        doc = Jsoup.connect("http://www.mydata.html").get();
        Toast.makeText(this, R.string.success, Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
    }

    Elements rows = doc.select("tr[class]");

    data = "<table>" + rows.toString() + "</table>";
    showResults();
}

protected void showResults(){
    WebView web = (WebView)findViewById(R.id.web);
    web.loadData(data, "text/html", "utf-8");
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState){
    savedInstanceState.putString(DATA, data);
    super.onSaveInstanceState(savedInstanceState);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
    if(savedInstanceState != null)
    {
        data = savedInstanceState.getString(DATA);
    }
    super.onRestoreInstanceState(savedInstanceState);
}
}

Flash/Flex developer here starting to get in to Android development, I must admit I am loving it so far, but obviously taking a long time to work out why things happen the way they do.

So the problem I have is that my app crashes without an Internet connection – The application (process.testing) has stopped unexpectedly. This only happens when there is no internet connection and works perfectly if there is one. The only part of my code that accesses the Internet is in a try catch block, can anyone see what I’m doing wrong or how I can handle the error when there is no Internet connection available?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:47:01+00:00Added an answer on May 24, 2026 at 4:47 am

    When you have no internet connection, doc is probably null and you get NullPointerException because you don’t check this case:

    Document doc = null;
    try {
        // connect throws an exception, doc still null
        doc = Jsoup.connect("http://www.mydata.html").get();
        Toast.makeText(this, R.string.success, Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
    }
    
    // dereferencing null (doc) throws NullPointerException
    Elements rows = doc.select("tr[class]");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a Java package providing funcionality like the .Net System.Data namespace ? Specificaly
Android provides various packages for testing like AndroidTestCase ApplicationTestCase InstrumentationTestCase ActivityInstrumentationTestCase2 ActivityTestCase I need
From django documentation: js_info_dict = { 'packages': ('your.app.package',), } urlpatterns = patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
info@s490up # gcc -std=gnu99 -o bla -g -O2 -DSunOS=1 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES= -I/usr/include/libxml2 -I/u/app/oracle/product/11.2/rdbms/demo -I/u/app/oracle/product/11.2/rdbms/public
Does anyone have examples of how to use DBMS_APPLICATION_INFO package with JBOSS? We have
I package our server releases into zip files using a batch file (Windows), running
I'm receiving Package Load Failure error when I open VS 2005 after I installed
I have an SSIS package, which depending on a boolean variable, should either go
What are some good package naming conventions for domain specific object models. For example,
I'd like to package a C# windows service project so it can be easily

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.