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

  • Home
  • SEARCH
  • 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 8346565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:03:48+00:00 2026-06-09T07:03:48+00:00

Hello I have been working on this project for a while and am very

  • 0

Hello I have been working on this project for a while and am very stuck at the moment, I am still new to Android and have been working on my first app which pulls information from an XML file that I create with MediaWiki API. Every time that I try to select the “Players” tab on my app, it force closes and I cannot figure out why. Here is the code that I have for my players Activity and Wikiparser activity:

package com.lvlup.kikurself.scotttest;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import java.io.IOException;
import org.xml.sax.SAXException;

//import com.lvlup.kikurself.scotttest.WikiParser.Cm;

public class scottPlayers extends ListActivity {
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

WikiParser p = new WikiParser();
ArrayList<String> titles = new ArrayList<String>();

try {
    p.parseInto(new URL("http://scottlandminecraft.wikia.com/api.php?action=query&list=categorymembers&cmtitle=Category:Players&cmlimit=500&format=xml"), titles);

} catch (MalformedURLException e) {
} catch (IOException e) {
} catch (SAXException e) {}

    //String[] values = new String[50]; 
    //values = res;




    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, titles);

    setListAdapter(adapter);

    final ListView playersList = getListView();


    playersList.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v, int position, long thisID)
    {
         Object o = (playersList.getItemAtPosition(position));
         String playerName_temp = (o.toString());

         Intent newIntent = new Intent(v.getContext(), playerDisp.class);
         newIntent.putExtra("tempN", playerName_temp);
         startActivity(newIntent);

    }
    });



    //get your data back again with: String fName = getIntent().getExtras().getInt("fname");




}}

And next the code for the WikiParser function:

package com.lvlup.kikurself.scotttest;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import android.sax.*;
import android.text.TextUtils;
import android.util.Xml;
import android.util.Xml.Encoding;

public class WikiParser {
private static class CmListener implements StartElementListener {
    final List<String> mTitles;
    CmListener(List<String> titles) {
        mTitles = titles;
    }
    @Override
    public void start(Attributes attributes) {
        String title = attributes.getValue("", "title");
        if (!TextUtils.isEmpty(title)) {
            mTitles.add(title);
        }
    }
}
public void parseInto(URL url, List<String> titles) throws IOException, SAXException {
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    try {
        parseInto(new BufferedInputStream(con.getInputStream()), titles);
    } finally {
        con.disconnect();
    }
}
public void parseInto(InputStream docStream, List<String> titles) throws IOException, SAXException {
    RootElement api = new RootElement("api");
    Element query = api.requireChild("query");
    Element categoryMembers = query.requireChild("categorymembers");
    Element cm = categoryMembers.requireChild("cm");
    cm.setStartElementListener(new CmListener(titles));
    Xml.parse(docStream, Encoding.UTF_8, api.getContentHandler());
}
}

There it is..I am here to learn my mistakes so anything that anyone can tell me about my code and what I can do to improve and if anyone has an idea whats going wrong, thank you in advance.

EDIT: Including LogCat also, thank you.

    08-06 04:33:58.837: D/dalvikvm(539): GC_FOR_ALLOC freed 62K, 3% free 9883K/10179K, paused 64ms
08-06 04:33:58.917: I/dalvikvm-heap(539): Grow heap (frag case) to 13.641MB for 4096016-byte allocation
08-06 04:33:59.037: D/dalvikvm(539): GC_CONCURRENT freed <1K, 3% free 13882K/14215K, paused 12ms+17ms
08-06 04:33:59.748: D/gralloc_goldfish(539): Emulator without GPU emulation detected.
08-06 04:34:05.977: D/AndroidRuntime(539): Shutting down VM
08-06 04:34:05.987: W/dalvikvm(539): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
08-06 04:34:06.067: E/AndroidRuntime(539): FATAL EXCEPTION: main
08-06 04:34:06.067: E/AndroidRuntime(539): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lvlup.kikurself.scotttest/com.lvlup.kikurself.scotttest.scottPlayers}: android.os.NetworkOnMainThreadException
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.os.Looper.loop(Looper.java:137)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.ActivityThread.main(ActivityThread.java:4340)
08-06 04:34:06.067: E/AndroidRuntime(539):  at java.lang.reflect.Method.invokeNative(Native Method)
08-06 04:34:06.067: E/AndroidRuntime(539):  at java.lang.reflect.Method.invoke(Method.java:511)
08-06 04:34:06.067: E/AndroidRuntime(539):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-06 04:34:06.067: E/AndroidRuntime(539):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-06 04:34:06.067: E/AndroidRuntime(539):  at dalvik.system.NativeStart.main(Native Method)
08-06 04:34:06.067: E/AndroidRuntime(539): Caused by: android.os.NetworkOnMainThreadException
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
08-06 04:34:06.067: E/AndroidRuntime(539):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-06 04:34:06.067: E/AndroidRuntime(539):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-06 04:34:06.067: E/AndroidRuntime(539):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
08-06 04:34:06.067: E/AndroidRuntime(539):  at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
08-06 04:34:06.067: E/AndroidRuntime(539):  at com.lvlup.kikurself.scotttest.WikiParser.parseInto(WikiParser.java:35)
08-06 04:34:06.067: E/AndroidRuntime(539):  at com.lvlup.kikurself.scotttest.scottPlayers.onCreate(scottPlayers.java:29)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.Activity.performCreate(Activity.java:4465)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-06 04:34:06.067: E/AndroidRuntime(539):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
08-06 04:34:06.067: E/AndroidRuntime(539):  ... 11 more
  • 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-09T07:03:49+00:00Added an answer on June 9, 2026 at 7:03 am

    NetworkOnMainThreadException

    The exception that is thrown when an application attempts to perform a networking operation on its main thread.

    This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it’s heavily discouraged. See the document Designing for Responsiveness.

    Also see StrictMode.

    Have a look at existing answers on Stackoverflow –

    1. NetworkOnMainThreadException

    2. android.os.NetworkOnMainThreadException

    and for more details you can get here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have been having trouble with this for a while now. I have
I have been working on this program for a while and I finally got
I have been working on this project for a few days, it’s a C#
hello im new to python and have been reading over the documentation and am
Hello android designers, 1-I have been wondering. Is it a good design approach to
I've been working on a hello-world sort of WebSocket app to see if I
i am working on an android database application and have fired query like this
Hello I've been working on this all morning. I thought it was a simple
I've been working on this for a while now, and can't seem to make
i have been working on a new .net MVC site and have integrated some

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.