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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:01:28+00:00 2026-06-17T02:01:28+00:00

I downloaded the jsoup library jsoup-1.7.1.jar core and imported it to my project using

  • 0

I downloaded the jsoup library jsoup-1.7.1.jar core and imported it to my project using the Project -> Properties->Java Build Path -> Add external Jars and I pasted the library file to my libs folder. However there seems to be some problem about importing the Jsoup library to my project. When I run my app, upon launching I get this error.

12-26 22:59:24.133: E/AndroidRuntime(6710): FATAL EXCEPTION: main
12-26 22:59:24.133: E/AndroidRuntime(6710): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jsouptest/com.example.jsouptest.MainActivity}: android.os.NetworkOnMainThreadException

After searching and asking I found out that eclipse sees the jsoup.jar, but unable to package it to APK file for the app to run. I tried to organize Imports by pressing Shift+Alt+O and I would get the same error. At this point, I am unsure about what is wrong and have no idea how to fix it. I have only hope someone will lead me toward the solution. Appreciate your time!

This is my code:

package com.example.jsouptest;

import java.io.IOException;

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

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         Document doc;
         try {
             doc = Jsoup.connect("http://google.com/").get();
             String title = doc.title();
          System.out.print(title);
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
         }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
  • 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-17T02:01:29+00:00Added an answer on June 17, 2026 at 2:01 am

    You have a

    android.os.NetworkOnMainThreadException
    

    Which has nothing to do with your jar working properly or not.

    The Exception is thrown by the new versions of Android so that you don’t lock the UI Thread (which is the main Thread) doing network operations.

    Use an AsyncTask (simple explanation about what each part of the AsyncTask does can be found here)or another Thread for network stuff. An Asynctask is easier to work with if you need to update the UI once the background work completes.

    An example of an AsyncTask with your code base can be:

    private class MyTask extends AsyncTask<Void, Void, String> {
    
      @Override
      protected String doInBackground(Void... params) {
        String title ="";
        Document doc;
        try {
          doc = Jsoup.connect("http://google.com/").get();
          title = doc.title();
          System.out.print(title);
        } catch (IOException e) {
          e.printStackTrace();
        }
        return title;   
      } 
    
    
      @Override
      protected void onPostExecute(String result) {        
        //if you had a ui element, you could display the title
        ((TextView)findViewById (R.id.myTextView)).setText (result);
      }
    }
    

    I assume:

    • The task is an inner class in your Activity.
    • You are forwarding the title gotten to a UI Element (eg a TextView) since that’s what AsyncTasks are usually used for.

    To call the AsyncTask, put this after setContentView(R.layout.activity_main);

    new MyTask().execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to download an external jar Jsoup by creating a packager.xml file.
I downloaded Android's Browser project (from git) and imported it to Eclipse. I cannot
I was trying to crawl some of website content, using jsoup and java combination.
Downloaded Reachability from Apple, using this method to check for an active connection: -(BOOL)isReachable{
I downloaded a project from TouchMyPixel and when I try to run it with
I downloaded the Facebook SDK for Android and I'm using it in my app
I downloaded a zip of source files containing a C# project with multiple entry
I just downloaded Jsoup to use in a program I'm writing in Eclipse. My
My app is using JSoup to download the HTML of a message board page
I downloaded NetBeans 6.5 complete pack with Java ME. And then I downloaded and

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.