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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:24:38+00:00 2026-06-15T15:24:38+00:00

package com.nicotera.colton.londontransitguide; import java.io.IOException; import java.text.DecimalFormat; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jsoup.*; import org.jsoup.nodes.Attributes;

  • 0
    package com.nicotera.colton.londontransitguide;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.*;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class RoutesActivity extends Activity implements OnItemSelectedListener {
    private static final String TAG = "RoutesActivity";

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

        Spinner spinner = (Spinner) findViewById(R.id.route_name_spinner); // Create an ArrayAdapter using the string array and a default spinner layout
        spinner.setOnItemSelectedListener(this);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.routes_array, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner
        spinner.setAdapter(adapter);
        Log.i(TAG, "spinner populated");
    }

    public void onItemSelected(AdapterView<?> parent, View view, 
            int pos, long id) {
        Log.i(TAG, "Item selected");
        int tempPos = pos;
        Log.i(TAG, ("Position of selected item: " + tempPos));
        int routeSelected;
        if (tempPos < 17)
            routeSelected = (tempPos + 1);
        else if (tempPos >= 17 && tempPos < 29)
            routeSelected = (tempPos + 2);
        else
            routeSelected = (tempPos + 3);
        String temp;
        if (routeSelected < 10)
            temp = ("0") + routeSelected;
        else
            temp = ("") + routeSelected;
        String url = "http://www.ltconline.ca/WebWatch/MobileAda.aspx?r=" + temp;
        try {
            urlParse(url);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public void urlParse (String url) throws IOException {
        Log.i(TAG, "Tried to parse url");
        String [] directions = new String [3];
        String [] directionNames = new String [3];
        Pattern routeDirPattern = Pattern.compile("\\&d=(\\d{1,2})");
        Connection conn = Jsoup.connect(url);
        /*LINE 82 */ Document doc = conn.get();
        int i = 0;
        Elements routeLinks = doc.select("a[href]");
        for (Element routeLink : routeLinks) {
            i = (i + 1);
            String name = routeLink.text();
            Attributes attrs = routeLink.attributes();
            String href = attrs.get("href");
            Matcher m = routeDirPattern.matcher(href);
            if (m.find()) {
                    String number = m.group(1);
                    directions [i] = number;
                    directionNames [i] = name;
                    Log.i(TAG, directionNames [i]);
            }
        }

    }


    public void onNothingSelected(AdapterView<?> parent) {
        // Another interface callback
    }
}

Apologies for the long code, but I figured I should just post it all so I don’t have to post it later. What is happening is the urlParse method is not working, specifically on line 82 (Not exactly line 82 since I deleted some comments before posting). Does anybody see what the issue is?

LogCat Posted below:

12-08 20:39:38.384: I/RoutesActivity(765): Item selected
12-08 20:39:38.384: I/RoutesActivity(765): Position of selected item: 0
12-08 20:39:38.394: I/RoutesActivity(765): Tried to parse url
12-08 20:39:38.454: D/AndroidRuntime(765): Shutting down VM
12-08 20:39:38.484: W/dalvikvm(765): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
12-08 20:39:38.505: E/AndroidRuntime(765): FATAL EXCEPTION: main
12-08 20:39:38.505: E/AndroidRuntime(765): android.os.NetworkOnMainThreadException
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
12-08 20:39:38.505: E/AndroidRuntime(765):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
12-08 20:39:38.505: E/AndroidRuntime(765):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12-08 20:39:38.505: E/AndroidRuntime(765):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
12-08 20:39:38.505: E/AndroidRuntime(765):  at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
12-08 20:39:38.505: E/AndroidRuntime(765):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:408)
12-08 20:39:38.505: E/AndroidRuntime(765):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
12-08 20:39:38.505: E/AndroidRuntime(765):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
12-08 20:39:38.505: E/AndroidRuntime(765):  at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
12-08 20:39:38.505: E/AndroidRuntime(765):  at com.nicotera.colton.londontransitguide.RoutesActivity.urlParse(RoutesActivity.java:82)
12-08 20:39:38.505: E/AndroidRuntime(765):  at com.nicotera.colton.londontransitguide.RoutesActivity.onItemSelected(RoutesActivity.java:62)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.widget.AdapterView.access$200(AdapterView.java:49)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:860)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.os.Handler.handleCallback(Handler.java:725)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.os.Looper.loop(Looper.java:137)
12-08 20:39:38.505: E/AndroidRuntime(765):  at android.app.ActivityThread.main(ActivityThread.java:5039)
12-08 20:39:38.505: E/AndroidRuntime(765):  at java.lang.reflect.Method.invokeNative(Native Method)
12-08 20:39:38.505: E/AndroidRuntime(765):  at java.lang.reflect.Method.invoke(Method.java:511)
12-08 20:39:38.505: E/AndroidRuntime(765):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-08 20:39:38.505: E/AndroidRuntime(765):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-08 20:39:38.505: E/AndroidRuntime(765):  at dalvik.system.NativeStart.main(Native Method)
  • 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-15T15:24:39+00:00Added an answer on June 15, 2026 at 3:24 pm

    This question arises on Stack Overflow almost every two days.
    It is because you cannot touch network from main thread.
    See my answer at

    Unfortunately, Msger has stopped. FATAL Exception: main

    Create a new class inside your RoutesActivity as

    public class RoutesActivity extends Activity{
    
    
    
    ........ blah blah
    
    
    
    private class MyInnerClass extends AsyncTask<String, Void, String> {
    
      String [] directions = new String [3];
      String [] directionNames = new String [3];     
    
       @Override
       protected void onPreExecute() {
       super.onPreExecute();
    
       }
    
       @Override
       protected String doInBackground(String... params) {
        try{
        Pattern routeDirPattern = Pattern.compile("\\&d=(\\d{1,2})");
        Connection conn = Jsoup.connect(params[0]);
        Document doc = conn.get();
        int i = 0;
        Elements routeLinks = doc.select("a[href]");
        for (Element routeLink : routeLinks) {
            i = (i + 1);
            String name = routeLink.text();
            Attributes attrs = routeLink.attributes();
            String href = attrs.get("href");
            Matcher m = routeDirPattern.matcher(href);
            if (m.find()) {
                    String number = m.group(1);
                    directions [i] = number;
                    directionNames [i] = name;
                    Log.i(TAG, directionNames [i]);
            }
        }
        }catch(Exception e){Log.d("doinbackground exception", e.toString());}
       return "Done";
       }
    
       @Override
       protected void onPostExecute(String result) {
       super.onPostExecute(result);
       // do whatever you wana do with directions[] and directionNames[] here
       }
    }
    }
    

    Change the following

    try {
            urlParse(url);
    } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
    

    to

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

Sidebar

Related Questions

package com.crumbin.tabs; //java package import java.io.IOException; import java.util.ArrayList; import org.json.JSONException; import android.app.Activity; import android.app.AlertDialog;
package com.VRG; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Context; import android.media.MediaPlayer;
package com.crumbin.tabs; import java.util.ArrayList; import java.util.HashMap; import org.apache.http.client.HttpClient; import android.content.Context; import android.database.Cursor; import android.location.Location;
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;
package com.org.myOxygen.activities; import java.util.Stack; import android.app.Activity; import android.app.ActivityGroup; import android.app.LocalActivityManager; import android.content.Intent; import android.os.Bundle;
Code: package com.parse; import org.w3c.dom.*; import javax.xml.xpath.*; import javax.xml.parsers.*; import java.io.IOException; import org.xml.sax.SAXException; public
package com.rest; import java.io.IOException; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button;
package com.nicotera.colton.londontransitguide; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.Spinner; public class RoutesActivity extends
This is my FragmentListArraySupport.java package com.test.methods; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.ListFragment; import android.util.Log;
debug.java package com.himanshu; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class BookShelfDebugActivity extends Activity

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.