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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:33:44+00:00 2026-06-06T18:33:44+00:00

I am trying to write code for getting my cords on the mobile. I

  • 0

I am trying to write code for getting my cords on the mobile.

I tried to debug the code and i guess error is in
LocationListener ll=new myLocationListener();

trackmobileclass

package prakash.work.trackmobile;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.widget.TextView;

public class getCords extends Activity {

TextView longi;
TextView lat;
TextView tv=(TextView) findViewById(R.id.tv);
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.get_cords);

    longi=(TextView) findViewById(R.id.longi);
    lat=(TextView) findViewById(R.id.lat);

    LocationManager lm=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
    LocationListener ll=new myLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);


}
class myLocationListener implements LocationListener{

    public void onLocationChanged(Location arg0) {
        if(arg0 != null)
        {
            tv.setText("Working");
            double plongi=arg0.getLongitude();
            double plat=arg0.getLatitude();

            longi.setText(Double.toString(plongi));
            lat.setText(Double.toString(plat));
        }

    }

    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub

    }

    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        // TODO Auto-generated method stub

    }

}
}

##XML layout file##

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Latitude"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/lat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Longitude"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/longi"
    android:text=""
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

##Manifest##

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="prakash.work.trackmobile"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
 android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission
android:name="android.permission.CONTROL_LOCATION_UPDATES" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".getCords"
        android:label="@string/title_activity_get_cords" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>


</manifest>

Or is there anything else i need to look into
How to work with listeners

  • 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-06T18:33:45+00:00Added an answer on June 6, 2026 at 6:33 pm

    TextView tv=(TextView) findViewById(R.id.tv);

    You need to put this in your public void onCreate(Bundle savedInstanceState) { method after setContentView(R.layout.get_cords);

    TextView longi;
    TextView lat;
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get_cords);
        tv=(TextView) findViewById(R.id.tv);
        longi=(TextView) findViewById(R.id.longi);
        lat=(TextView) findViewById(R.id.lat);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Visual Studio, and I'm just trying to write code as efficiently
I'm trying to write a tokenizer, but I'm getting a parse error: %*************************** parse
I am trying to write naive bayes classifier and I keep getting this error:
I m trying write code that after reset set up rrpmax as 3000. It
I'm trying to write code in my controller that when run, will create a
I'm trying to write code that will load an image from a resource, and
I've been trying to write code that loads a .png file, attaches hotspot information,
Alright, here I am again trying to write code from scratch and I can't
Trying to write a code at the moment that basically tests to see if
I'm trying to write a code to actually sort my array in an ascending

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.