locationmanager,getLatitude function

by CSUIDL PROGRAMMEr » Thu, 23 Oct 2008 19:31:57 GMT


Sponsored Links
 Hello,
I am a newbie android developer. I am trying to simulate gps
functionality in android sdk 1.0.

I am using location manager  to get getlatitude function.

 http://pastebin.com/m56feb30c 

I am loading a google kml  through my ddms.

I get a java null pointer exception.
What am i doing wrong here

Thanks

--~--~---------~--~----~------------~-------~--~----~



locationmanager,getLatitude function

by Mast3rpyr0 » Thu, 23 Oct 2008 21:19:09 GMT


 does getLastKnownLocation have a location to give yet? try running
maps first then run your app



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


locationmanager,getLatitude function

by nkijak » Thu, 23 Oct 2008 21:24:48 GMT


 Hello,

I updated your code on that site to be more "correct". You should
stick with the static variable instead of hardcoding the string "gps".

You get a null pointer because you have to provide a location first,
meaning run the KML, then you can call getLastKnownLocation. When the
emulator starts, without being given a coordinate, it has no last
location. So try running the KML then running your app.

If you are trying to get continuous updates of location you should
implement LocationListener instead.

Nick



--~--~---------~--~----~------------~-------~--~----~



locationmanager,getLatitude function

by CSUIDL PROGRAMMEr » Mon, 03 Nov 2008 12:26:17 GMT


 Hello nkijak,
I could not find your upated code.
Also, i tried running the maps, ( including kml file, manually sending
decimal) .But the Nullpointer exception exists.
Is there anyone here who as got gps simulation working in android
here.
Thanks




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. two lines in a row list view

Hello all,

I am trying to get two lines in the same row in a list view and I
looked at some things online but found it hard to apply to what I am
trying to achieve.

Could anyone look at my code please and suggest me how I can make it
possible. Thanks


package com.varun.HelloListView;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class HelloListView extends ListActivity {
        TextView selection;
        ArrayAdapter a1=null;
        ArrayAdapter a2=null;
        ArrayAdapter a3=null;
        ArrayAdapter a4=null;
        ArrayAdapter a5=null;
        ArrayAdapter a6=null;
        ArrayAdapter a7=null;
        ArrayAdapter a8=null;
        ListActivity myActivity = null;

        @Override
        public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                a1 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text1,AndroidPhones1);
                a2 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text1,AndroidPhones2);
                a3 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text1,AndroidPhones3);
                a4 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text1,AndroidPhones4);
                a5 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text2,line2);
                a6 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text2,line2);
                a7 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text2,line2);
                a8 = new ArrayAdapter(this, R.layout.two_line_list_item,
R.id.text2,line2);





                setContentView(R.layout.main);
                setListAdapter(a1);
                setListAdapter(a5);

                myActivity = this;

                Button next1 = (Button) findViewById(R.id.Button1);
    next1.setOnClickListener(
                new View.OnClickListener() {
                        public void onClick(View view) {
                                        myActivity.setListAdapter(a1);
                                        myActivity.setListAdapter(a5);

                                        a1.notifyDataSetChanged();
                                        a5.notifyDataSetChanged();
                        }
        }
        );

                //setListAdapter(a2);
                //myActivity = this;
                Button next2 = (Button) findViewById(R.id.Button2);
    next2.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        myActivity.setListAdapter(a2);
                                        a2.notifyDataSetChanged();
                                }
                  }
                );

                //setListAdapter(a3);
                //myActivity = this;
                Button next3 = (Button) findViewById(R.id.Button3);
    next3.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view) {
                                        myActivity.setListAdapter(a3);
                                        a3.notifyDataSetChanged();

                                }
                        }
                );

    //setListAdapter(a4);
                //myActivity = this;
                Button next4 = (Button) findViewById(R.id.Button4);
    next4.setOnClickListener(
                        new View.OnClickListener() {
                                public void onClick(View view4) {
                                        myActivity.setListAdapter(a4);
                                        a4.notifyDataSetChanged();
                                }
                        }
        );

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                super.onCreateOptionsMenu(menu);

                menu.add(0, Settings.ENTER_FOOD, 0, "Enter Food");
                menu.add(0, Settings.ANALYZE_FOOD, 0, "Analyze Food");
                menu.add(0, Settings.SETTINGS, 0, "Settings");

                return true;
        }


        static final String[] AndroidPhones1 = new String[] {
                "HTC Evo 1G",  "Google Nexus One", "Motorola Devour",
                "Motorola CLIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };

        static final String[] AndroidPhones2 = new String[] {
                "HTC Evo 2G",  "Google Nexus One", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };

        static final String[] AndroidPhones3 = new String[] {
                "HTC Evo 3G",  "Google One", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };

        static final String[] AndroidPhones4 = new String[] {
                "HTC Evo 4G",  "Google Nexus hello", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };
        static final String[] line2 = new String[] {
                "HTC Evo 4G",  "Google Nexus hello", "Motorola Devour",
                "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid",
                "myTouch 3G Slide", "Droid Eris", "Motorola Backflip",
                "Motorola i1", "HTC Hero", "myTouch 3G Fender",
                "HTC Droid Incredible",  "Samsung Moment", "LG Ally ",
        };
        }

-- 

2. should i use a service or local thread ?

I have an application which requires networking service.
I took on LWUIT4IO and adjusted it to my needs so now i have a network
queue that can run one or more network threads.

Now, my application is based on single root activity that spawns other
child activities as needed (it's a reservation center for vacations,
car rental etc.. each in it's own activity).
The network is common to all and should be used by all activities. the
network thread requires, basically, a callback to notify it's finished
and return the result (input stream or byte array) .

At first i thought that i should use a service instead of a singleton
that will be started in the root activity(the  service will also be
started in the root activity), however working with a local service is
problematic for me:
1. no callbacks which makes me use intents to encapsulate the request
\response in intents - time consuming, also since there is not single
point of listening (i have to use BroadcastReceivers)  i have to add a
calling class name or some other identifier so the sender of the
request will know it's for him, i think this is also a waste of time
and resources since  i need only one listener.
2. i think i CAN use callbacks if i use Binder object to return local
instance of my Service and then use the queuing method directly, this
is problematic for me as acquiring Binder object is asynchronous and i
need it 'on the spot'
3. I thought of using a static instance of the service and null it in
onDestroy of the service, but if i use that way, i'm not so sure i
need a service...
4. i saw a small answer in stackoverflow about inheriting application
and putting whatever member you need there so when you use
getApplication you get this instance and then you can retrieve
whatever you want, is this even advisable ?

In short i'm not so sure Service is what i should use, any advise here
would be great...

Eyal.

-- 

3. getProtectionDomain returns nul

4. Retrieve android:versionName from Library Project

5. Example of adding custom contact group using sdk 1.6

6. How to control UART on Android OS

7. why no BluetoothAdapter.ACTION_REQUEST_DISABLE ???