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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:38:27+00:00 2026-06-01T06:38:27+00:00

Hello Android programmers, I am making a currency application and to do this, I

  • 0

Hello Android programmers,

I am making a currency application and to do this, I am getting my currency rates from the following website (that returns json):

https://raw.github.com/currencybot/open-exchange-rates/master/latest.json

Here is the method in my program that gets all of the rates found on the website.

public String[] fetchCurrencyRates()
{
    String[] currencyValues = new String[currency_array.length]; //currency_array has the names of all the currencies
    try
    {
        URL currency = new URL("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json");
        URLConnection c = currency.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
        String line;
        while ((line = in.readLine()) != null)
        {
            JSONArray ja = new JSONArray(line);
            for (int i = 0; i < ja.length(); i++)
            {
                JSONObject jo = (JSONObject) ja.get(i);
                currencyValues[i] = (jo.getString("rates"));
            }
        }
    }
    catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (JSONException e) {
    e.printStackTrace();
    }
    return currencyValues;
}

This method does not work for some reason. I will now post the LogCat in order to help me debug this method.

03-29 13:42:21.323: E/AndroidRuntime(678): FATAL EXCEPTION: main
03-29 13:42:21.323: E/AndroidRuntime(678): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sapra.currency/com.sapra.currency.TheUltimateCurrencyConverterActivity}: android.os.NetworkOnMainThreadException
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.os.Looper.loop(Looper.java:137)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.ActivityThread.main(ActivityThread.java:4424)
03-29 13:42:21.323: E/AndroidRuntime(678):  at java.lang.reflect.Method.invokeNative(Native Method)
03-29 13:42:21.323: E/AndroidRuntime(678):  at java.lang.reflect.Method.invoke(Method.java:511)
03-29 13:42:21.323: E/AndroidRuntime(678):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-29 13:42:21.323: E/AndroidRuntime(678):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-29 13:42:21.323: E/AndroidRuntime(678):  at dalvik.system.NativeStart.main(Native Method)
03-29 13:42:21.323: E/AndroidRuntime(678): Caused by: android.os.NetworkOnMainThreadException
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
03-29 13:42:21.323: E/AndroidRuntime(678):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
03-29 13:42:21.323: E/AndroidRuntime(678):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
03-29 13:42:21.323: E/AndroidRuntime(678):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
03-29 13:42:21.323: E/AndroidRuntime(678):  at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
03-29 13:42:21.323: E/AndroidRuntime(678):  at com.sapra.currency.TheUltimateCurrencyConverterActivity.fetchCurrencyRates(TheUltimateCurrencyConverterActivity.java:60)
03-29 13:42:21.323: E/AndroidRuntime(678):  at com.sapra.currency.TheUltimateCurrencyConverterActivity.onCreate(TheUltimateCurrencyConverterActivity.java:51)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.Activity.performCreate(Activity.java:4465)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-29 13:42:21.323: E/AndroidRuntime(678):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-29 13:42:21.323: E/AndroidRuntime(678):  ... 11 more

I have confirmed that this method is the cause of the problem, as I commented out the call to this method and the program did function as expected.

  • 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-01T06:38:29+00:00Added an answer on June 1, 2026 at 6:38 am

    You are trying to fetch your JSON data via the web from the main thread. Starting in API lvl 10 or 11 I think this will raise an exception. Consider it the people who make the platform’s way of telling you that it is a very bad idea to do network operations on the main thread. Move your call into a AsyncTask or use the Thread / Handler pattern to accomplish your work in the background.

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

Sidebar

Related Questions

Hello Android programmers, I am working on parsing a website in my application. This
Hello dear programmers, I am very new to android application development and for practice
Hello Android programmers, I was trying to make a screen that has an EditText
Hello my favorite help resource... I am a average android programmer making an application
When I tried to do a simple modification of the hello android program that
I have developed the Hello World Android application using Eclipse. I can run the
Hello sir i send the arraylist through url pass from android to php all
hello fellow programmers, I followed a tutorial at http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php to send a String encrypted
Hello android developers, I was struggling to get this work but failed and now
I am practicing from the book Hello,Android ed3.There is an example code on creating

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.