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 8510125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:37:12+00:00 2026-06-11T03:37:12+00:00

package com.example.application; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import org.jsoup.Jsoup; import org.jsoup.nodes.Document;

  • 0
package com.example.application;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import com.example.androidtablayout.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;


public class PhotosActivity extends Activity  {

    public void onCreate(Bundle savedInstanceState) {


        String htmlCode = "";

            Document doc;
              try {
                  //Problem start
            doc = Jsoup.connect("http://www.example.com/").get();
            Element content = doc.select("a").first();
                    String variable = content.text();
                  // Problem end
                    TextView t = new TextView(this);
                    t=(TextView)findViewById(R.id.textView3); 
                    t.setText(variable);
               } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }

            super.onCreate(savedInstanceState);
            setContentView(R.layout.photos_layout);

    }
}

My problem is with JSoup framework. Between of “Problem” lines. I take the “Unexpectedly Stopped Error”.

When I put the “htmlCode” variable like this

t.SetText(htmlCode); 

It is work but i get all of html source code .

What is the main problem , i can’t get it.

  • 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-06-11T03:37:13+00:00Added an answer on June 11, 2026 at 3:37 am

    There’s a lot wrong with your code:

    • super.onCreate() should always be the very first call in your own onCreate()

    • You call setContentView() at the very end but try to findViewById() before that in the catch clause. At that point, your Activity has no content view yet, so findViewById() will return null — the resulting NullPointerException is most likely why your code crashes.

    • You do IO on the UI thread. Don’t do that, Android will force-quit your app because IO is unpredictable and your app will be unresponsive, this is even worse with network IO. Check out AsyncTask on how to do IO off the UI thread and then asynchronously update your TextView.

    Also, check out logcat. For most crashes, it will contain a stacktrace that will pinpoint where things went wrong.


    Here’s a reworked version of your code that follows some of the advice I’ve given.

    Please note that I did not have the time to fix the most important issue: This code still does IO on the UI thread. It should use an AsyncTask instead!

    public class PhotosActivity extends Activity {
    
      // Use a string constant to "tag" log statements that belong to the same
      // feature/module of your app. This activity does something with "photos" so
      // use that as a tag. It's the first parameter to Android's Log methods.
      private static final String TAG = "photos";
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); // Always call super.onCreate() first.
        setContentView(R.layout.photos_layout); // Then load the layout.
    
        // Find textView3 in layout and set it's text to HTML code.
        // There's no need to create a new TextView() here.
        TextView textView = (TextView) findViewById(R.id.textView3);
        textView.setText(getHtmlCode());
      }
    
      // Structure your code. If it's a larger block that does one thing,
      // extract it into a method.
      private String getHtmlCode() {
        try {
          Document doc = Jsoup.connect("http://www.example.com/").get();
          Element content = doc.select("a").first();
          return content.text();
        } catch (IOException e) {
          // Never e.printStackTrace(), it cuts off after some lines and you'll
          // lose information that's very useful for debugging. Always use proper
          // logging, like Android's Log class, check out
          // http://developer.android.com/tools/debugging/debugging-log.html
          Log.e(TAG, "Failed to load HTML code", e);
          // Also tell the user that something went wrong (keep it simple,
          // no stacktraces):
          Toast.makeText(this, "Failed to load HTML code",
              Toast.LENGTH_SHORT).show();
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
package com.example.temp_application; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.EditText;
Main Activity Code. BroadcastExample.java package com.example.broadcast; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class
Here is My Whole Code....... BroadcastExample.java package com.example.broadcast; > import android.app.Activity; import > android.content.Context;
I'm trying out the LoaderCursor example in the API Demo: package com.example.android.apis.app; import android.app.Activity;
Android kills my service in the package com.net.myspeechservice under some certain scenarios, for example
This is my code: package com.example.testcode; import android.app.ListFragment; import android.app.LoaderManager; import android.content.CursorLoader; import android.content.Loader;
I have the following servlet coded in /src/main/java/examples/web/SimpleServlet.java : package examples.web; import java.io.IOException; import
Does anybody know why my getAltitude in the following always returns 0? package com.example.helloandroid;
This confuses me. The following compiles fine under Eclipse. package com.example.gotchas; public class GenericHelper1

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.