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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:02:29+00:00 2026-06-09T03:02:29+00:00

I’m trying to use Google Map in Android Application. MainActivity contains EditText, ImageButton and

  • 0

I’m trying to use Google Map in Android Application. MainActivity contains EditText, ImageButton and MapView. When user gives some query and taps ImageButton, MainAcitivity is supposed to get some JSON data from a url and then I need to use that JSON data to create Markers and dialogBox when user clicks those Markers. Whenever I run the application, it runs fine. But when I click ImageButton, application stops giving logcat error NetworkOnMainThreadException and StrickMode$AndroidBlockGuardPolicy. I’ve attached logcat output and MainActivity. I’ve run this JSON program creating other test project and it is working just fine. But when I add it to MainAcitivity, it doesn’t work. I believe, android’s security policies are stopping it from getting data from url.

So what is the reason of this error and how can I make this Activity work?
Thank You very much friends for paying attention.
Tell me if you need more code for CustomOverlayItem object or JSON object.

public class MainActivity extends MapActivity {

        private List<Home> listHome = new ArrayList<Home>();

        @Override
        public void onCreate(Bundle savedInstanceState) {

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

            MapView mv_map = (MapView) findViewById(R.id.mv_map);
            MapController mapController = mv_map.getController();
            mv_map.setBuiltInZoomControls(true);
            mapController.setZoom(5);
            Markers markers = new Markers(this.getResources().getDrawable(
                    R.drawable.ic_action_home), this);
            CustomOverlayItem items = new CustomOverlayItem(getuserLocation(),
                    "Checking", "Checking");
            List<Overlay> overlays = mv_map.getOverlays();
            markers.addOverlayItem(items);
            overlays.add(markers);

            ImageButton ib_search = (ImageButton) findViewById(R.id.ib_search);
            ib_search.setOnClickListener(new OnClickListener() {

            @Override
                public void onClick(View v) {
                    Json json = new Json();
                    listHome = json.getListHome();
                    EditText editText = (EditText) findViewById(R.id.et1_search);
                    editText.setText(listHome.get(0).getTitle().toString());
                }
            });

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }

        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }

        private GeoPoint getuserLocation() {
                GeoPoint geoPoint = new GeoPoint(19240000, -99120000);
            return geoPoint;
        }
    }

Logcat Output : errors

08-04 16:26:55.253: E/Trace(1307): error opening trace file: No such file or directory (2)
08-04 16:26:57.743: E/MapActivity(1307): Couldn't get connection factory client
08-04 16:27:01.643: E/AndroidRuntime(1307): FATAL EXCEPTION: main
08-04 16:27:01.643: E/AndroidRuntime(1307): android.os.NetworkOnMainThreadException
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at java.net.URL.openStream(URL.java:462)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at com.incubers.map.json.Json.getListHome(Json.java:33)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at com.incubers.map.MainActivity$1.onClick(MainActivity.java:53)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.view.View.performClick(View.java:4084)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.view.View$PerformClick.run(View.java:16966)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.os.Handler.handleCallback(Handler.java:615)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.os.Looper.loop(Looper.java:137)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at java.lang.reflect.Method.invokeNative(Native Method)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at java.lang.reflect.Method.invoke(Method.java:511)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-04 16:27:01.643: E/AndroidRuntime(1307):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-04 16:27:01.643: E/AndroidRuntime(1307):     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-09T03:02:31+00:00Added an answer on June 9, 2026 at 3:02 am
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
        .detectAll()
        .penaltyLog()
        .penaltyDialog()
        .build());
    

    refer this

    You can also avoid IO related tasks on main thrread/

    Use Handler,AsyncTask and post result on UI.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.