Problem with running and application

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Problem with running and application

Postby smbogdan » Mon May 30, 2011 1:27 pm

I don't understand why my application doesn't work with this string
Code: Select all
LocationManager locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
, I searced along the forum and I found this... The compiler doesn't give me any errors but when I run it on my device I get
Sorry! Sudden interruption of the application
. Do you know what is the problem?
smbogdan
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 10, 2011 4:52 pm

Top

Re: Problem with running and application

Postby abhijitphatak28 » Wed Jun 01, 2011 9:45 am

I used this location manger plentry of time and never found this issue. You could try switching to any other device and then let us know if the problem still persist.
User avatar
abhijitphatak28
Senior Developer
Senior Developer
 
Posts: 102
Joined: Sat Feb 12, 2011 1:18 pm
Location: Indore

Re: Problem with running and application

Postby smbogdan » Thu Jun 02, 2011 4:51 pm

Ok I will look for another device then I will try.
smbogdan
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 10, 2011 4:52 pm

Re: Problem with running and application

Postby smbogdan » Fri Jun 03, 2011 6:22 pm

I tryed on another device and I get the same error... Could you see what is wrong please?

Main.java:
Code: Select all
package org.example.LocationTest;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity implements LocationListener{
   private LocationManager myManager;
   private TextView tv;
   Toast t;
   
   /**************************************************************************
    * View overrides below
    **************************************************************************/
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
   
      
      // get a handle to our TextView so we can write to it later
   
      
      // set up the LocationManager
      myManager = (LocationManager) getSystemService(LOCATION_SERVICE);   
   }

   @Override
   protected void onDestroy() {
      stopListening();
      super.onDestroy();
   }
   
   @Override
   protected void onPause() {
      stopListening();
      super.onPause();
   }
   
   @Override
   protected void onResume() {
      startListening();
      super.onResume();
   }



   /**************************************************************************
    *  helper functions for starting/stopping monitoring of GPS changes below
    **************************************************************************/
   private void startListening() {
      myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
   }

   private void stopListening() {
      if (myManager != null)
         myManager.removeUpdates(this);
   }




   /**************************************************************************
    * LocationListener overrides below
    **************************************************************************/
   @Override
   public void onLocationChanged(Location location) {
      Log.i(getClass().getSimpleName(), "accuracy: " + location.getAccuracy());
      
      // we got new location info. lets display it in the textview
      String s = "";
      
      s += "\tLatitude:  " + location.getLatitude()  + "\n";
      s += "\tLongitude: " + location.getLongitude() + "\n";

      
   
      t.setText(s);
      t.show();
      t.makeText(getApplicationContext(), s, 500);
   }

   @Override
   public void onProviderDisabled(String provider) {}

   @Override
   public void onProviderEnabled(String provider) {}

   @Override
   public void onStatusChanged(String provider, int status, Bundle extras) {}
}


AndroidManifest.xml:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="org.example.LocationTest"
   android:versionCode="1"
   android:versionName="1.0">
   <application
      android:icon="@drawable/icon"
      android:label="@string/app_name">
      <activity
         android:name=".Main"
         android:label="@string/app_name">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
   <uses-sdk android:minSdkVersion="3" />
       <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS">
    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_LOCATION">
    </uses-permission>
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
smbogdan
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 10, 2011 4:52 pm

Re: Problem with running and application

Postby adidmafioso » Sat Jun 04, 2011 12:04 pm

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyLocationListener locationListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 100, locationListener);
location=new Location(LocationManager.GPS_PROVIDER);

where My location listener class just implements LocationListener interface.You dont need to do anything in this class.Just get a class that implements the above mentioned interface.

Try it out.If any prob write to me i'l post the entire code.
adidmafioso
Developer
Developer
 
Posts: 33
Joined: Mon Sep 21, 2009 9:30 pm
Location: delhi

Re: Problem with running and application

Postby smbogdan » Mon Jun 06, 2011 7:47 pm

Thank you for help, but I get some errors:
Code: Select all
The method getSystemService(String) is undefined for the type Main
, I don't know if it's correct if I create it like this:
Code: Select all
   private LocationManager getSystemService(String locationService) {
   // TODO Auto-generated method stub
   return null;
}
it's what eclipse gives me;

Code: Select all
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 100, locationListener);
this line gives me:
Code: Select all
Multiple markers at this line
   - Syntax error on tokens, TypeArgument1 expected
    instead
   - Syntax error on token "(", < expected
how should I proceed?
smbogdan
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 10, 2011 4:52 pm

Top

Re: Problem with running and application

Postby da3dalu5 » Tue Jun 07, 2011 11:18 am

smbogdan wrote:I don't understand why my application doesn't work with this string
Code: Select all
LocationManager locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
, I searced along the forum and I found this... The compiler doesn't give me any errors but when I run it on my device I get
Sorry! Sudden interruption of the application
. Do you know what is the problem?



have you tried:
LocationManager locman = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);


That is how I am doing it in my code and it's working, well that part of the code is anyway! haha

~D
~D

“If you only do what you know you can do- you never do very much.”
da3dalu5
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Apr 05, 2011 10:52 am

Re: Problem with running and application

Postby smbogdan » Fri Jun 10, 2011 4:30 pm

I still get these errors:
Code: Select all
   - Syntax error on token "(", < expected
   - Syntax error on tokens, TypeArgument1 expected

How should I fix them?
smbogdan
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 10, 2011 4:52 pm

Re: Problem with running and application

Postby da3dalu5 » Mon Jun 13, 2011 11:41 am

smbogdan wrote:I still get these errors:
Code: Select all
   - Syntax error on token "(", < expected
   - Syntax error on tokens, TypeArgument1 expected

How should I fix them?


could you post up you're latest code? (if different from the code that you have uploaded previously)

I had a look through your code that you have posted so far and have not really spotted anything, I did make one or two changes tho, if you want to try running that version?

Code: Select all
package Hartford.gps;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity implements LocationListener{
   private LocationManager myManager;
   private TextView tv;
   Toast t;

   /**************************************************************************
    * View overrides below
    **************************************************************************/
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);


      // get a handle to our TextView so we can write to it later


      // set up the LocationManager
      myManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);   
   }

   @Override
   protected void onDestroy() {
      stopListening();
      super.onDestroy();
   }

   @Override
   protected void onPause() {
      stopListening();
      super.onPause();
   }

   @Override
   protected void onResume() {
      startListening();
      super.onResume();
   }



   /**************************************************************************
    *  helper functions for starting/stopping monitoring of GPS changes below
    **************************************************************************/
   private void startListening() {
      myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
      
   }

   private void stopListening() {
      if (myManager != null)
         myManager.removeUpdates(this);
   }




   /**************************************************************************
    * LocationListener overrides below
    **************************************************************************/
   @Override
   public void onLocationChanged(Location location) {
      Log.i(getClass().getSimpleName(), "accuracy: " + location.getAccuracy());

      // we got new location info. lets display it in the textview
      String s = "";

      s += "\tLatitude:  " + location.getLatitude()  + "\n";
      s += "\tLongitude: " + location.getLongitude() + "\n";



      t.setText(s);
      t.show();
      Toast.makeText(getApplicationContext(), s, 500);
   }

   @Override
   public void onProviderDisabled(String provider) {}

   @Override
   public void onProviderEnabled(String provider) {}

   @Override
   public void onStatusChanged(String provider, int status, Bundle extras) {}
}


But I'm not sure if it will fix the problem for you. I have a program that uses gps if you want to have a look at that code and see if something clicks with you?

http://www.anddev.org/map-problems-f26/getting-gps-location-calculating-speed-and-showing-on-a-map-t53427.html

The most recent code is in my last post down the bottom of the page
~D

“If you only do what you know you can do- you never do very much.”
da3dalu5
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Apr 05, 2011 10:52 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests