user1325591
user1325591

Reputation: 45

Error: cannot find symbol: method startActivity

I am developing an application in order to connect to Google Navigator by the following code..

import android.app.Activity; 
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public static void Call_GoogleMapsNavigation(int longitud,int latitud)
{
Intent i = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("google.navigation:q=" +latitud+ ","+longitud+"")); 
Context.startActivity(i); 
}

... but I get the following error:

Error returned:

GWDCPSET_GlobalProcedures_MobileDevice.java:1223: cannot find symbol
symbol : method startActivity(android.content.Intent)
location: class antay.cfsatv30.wdgen.GWDCPSET_GlobalProcedures_MobileDevice
startActivity(i); 
^

I can not find the solution to the problem ...

Thank you very much,

Upvotes: 1

Views: 14557

Answers (3)

Ahmed Youssef
Ahmed Youssef

Reputation: 1

Uri.parse("google.navigation:q=" +latitud+ ","+longitud+""));

getContext.startActivity(i); //to get the context the method is called in

Upvotes: 0

ChrisCarneiro
ChrisCarneiro

Reputation: 352

To explain a bit further the answer above. What it means is that you can't/shouldn't not call statically startActivity(intent).

Context.startActivity(intent); //wrong notice capital 'C'

You need a Context instance.

So, the simplest thing to do, is add a parameter to your static method: (Notice lowercase 'c' as a convention for method names in Java)

public static void call_GoogleMapsNavigation(final Context context, int longitud,int latitud) { 

        ...
        context.startActivity(i); //right
}

So for example in your activity or any component in your app that holds a reference to a context instance, you call your method as follows

For simplicity I assume you call it from an activity(always holds a reference to a context):

MainActivity extends AppCompatActivity { 

    OnCreate(Bundle savedInstance) {
        <YourHelperClass>.callGoogleMapsNavigation(this, 23, 44); //static call
    }
}

Hope this helps :)

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

Try this way :

Context oContext;
oContext= mContext;
Intent i = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("google.navigation:q=" + latitud+ "," + longitud));
oContext.startActivity(i);

Upvotes: 0

Related Questions