Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Location-Based App
    primarykey
    data
    text
    <p>I need a help with my app. I've been trying yo build a simple location app. Therefore, I followed the Android Developer Training (<a href="http://developer.android.com/training/location/retrieve-current.html" rel="nofollow">http://developer.android.com/training/location/retrieve-current.html</a>). However, I am stuck with the last part. My app seems to crash whenever it hits this code, </p> <pre><code>mLocationClient.connect(); </code></pre> <p>I've added permission and activated location service in my device. Can anyone help me?</p> <p>This is my whole code.</p> <pre><code>public class MainActivity extends FragmentActivity implements ConnectionCallbacks, OnConnectionFailedListener{ private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000; private LocationClient mLocationClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLocationClient = new LocationClient(this, this, this); } @Override protected void onStart(){ super.onStart(); mLocationClient.connect(); } @Override protected void onStop(){ mLocationClient.disconnect(); super.onStop(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public static class ErrorDialogFragment extends DialogFragment{ private Dialog mDialog; public ErrorDialogFragment(){ super(); mDialog = null; } public void setDialog(Dialog dialog){ mDialog = dialog; } @Override public Dialog onCreateDialog(Bundle savedInstanceState){ return mDialog; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (requestCode) { case CONNECTION_FAILURE_RESOLUTION_REQUEST : switch (resultCode) { case Activity.RESULT_OK: break; default: break; } default: break; } } private boolean servicesConnected() { int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (ConnectionResult.SUCCESS == resultCode) { Log.d("Location Update", "Google Play Services is available"); return true; } else { Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 0); if (dialog != null) { //ErrorDialogFragment errorFragment = new ErrorDialogFragment(); //errorFragment.setDialog(dialog); //errorFragment.show(getFragmentManager(), "Location Updates"); //errorFragment.show(getSupportFragmentManager(), "Location Updates"); } return false; } } @Override public void onConnectionFailed(ConnectionResult connectionResult) { // TODO Auto-generated method stub if (connectionResult.hasResolution()) { try { connectionResult.startResolutionForResult( this, CONNECTION_FAILURE_RESOLUTION_REQUEST); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); } } else { showErrorDialog(connectionResult.getErrorCode()); } } private void showErrorDialog(int errorCode) { Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog( errorCode, this, CONNECTION_FAILURE_RESOLUTION_REQUEST); if (errorDialog != null) { ErrorDialogFragment errorFragment = new ErrorDialogFragment(); errorFragment.setDialog(errorDialog); } } @Override public void onConnected(Bundle arg0) { // TODO Auto-generated method stub Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show(); } @Override public void onDisconnected() { // TODO Auto-generated method stub Toast.makeText(this, "Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload