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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:03:42+00:00 2026-05-26T17:03:42+00:00

I have method which return the latitude of the location public double[] getlat(){ double

  • 0

I have method which return the latitude of the location

public double[] getlat(){
     double lat[]=new double[20];

     JSONObject json = JSONFunction.getJSONfromURL("https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=1000&types=bank&sensor=true&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");    
try{
    JSONArray  JArray = json.getJSONArray("results");
       Log.v(TAG, "getting results");
    for(int i=0;i<JArray.length();i++){                     
        JSONObject e = JArray.getJSONObject(i);
        JSONObject location=e.getJSONObject("geometry").getJSONObject("location");
        lat[i] = location.getDouble("lat");     
}catch(JSONException e)        {
     Log.e("log_tag", "Error parsing data "+e.toString());
}

return lat;

}

I recieved this array in main activity as

    public class Test extends Activity {
   private static final String TAG = "test";

/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle icicle) {
    // Be sure to call the super class.
    super.onCreate(icicle);
     StringBuilder sb =new StringBuilder();
    double a[]=getlat();
    for(int i=0;i<a.length;i++) {
        sb.append(a[i]+"\n");
    }
 TextView tv=(TextView)findViewById(R.id.text);
 tv.setText(sb);
 }

Giving me nullpointor exception but in logcat i can see the latitude array displayed
The problem is in returing the lat.
Correct me where i am wrong..

  • 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-05-26T17:03:43+00:00Added an answer on May 26, 2026 at 5:03 pm

    you din’t use setContentView() in the onCreate() method..

    tv.setText(sb); , so this line is giving you the error.. as it can’t find the textView.

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

Sidebar

Related Questions

I have a method on a WCF proxy which returns void. If the return
I have a GridView which I am populating by calling a method to return
I have a method which should return a snapshot of the current state, and
I have written method which should return string with data from select query, but
I have a method below which converts an address to longtitude/latitude. LatLng is a
I have a method which should return a list of anonymous objects with a
I have a small method which return true or false if a timestamp is
I have a method which will return two strings in an array, split(str, :,
I have this method which return an array of string : private static string[]
I have following method which is failing . I think I am comparing double

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.