>

Fórum

Fórum da RL System, voltado para analistas, programadores etc. Tudo sobre linguagem de programação e desenvolvimento Full Stack: Banco de Dados, Android, C#, Java, .NET, PHP, Node, Javascript, TypeScript, Front, HTML e muito mais.



Erro ao tentar localizar latitude e longitude.


Estou com o mesmo problema abordado neste tópico http://rlsystem.com.br/forum/android/545-erro-ao-tentar-pegar-latitude-e-longitude#top.
Não entra no método onLocationChanged e nem ativa a barra de progresso. Abaixo está o log cat:

06-13 09:50:52.177: E/AndroidRuntime(4151): FATAL EXCEPTION: main
06-13 09:50:52.177: E/AndroidRuntime(4151): java.lang.IllegalStateException: Could not execute method of the activity
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.view.View$1.onClick(View.java:2144)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.view.View.performClick(View.java:2485)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.view.View$PerformClick.run(View.java:9080)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.os.Handler.handleCallback(Handler.java:587)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.os.Handler.dispatchMessage(Handler.java:92)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.os.Looper.loop(Looper.java:130)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-13 09:50:52.177: E/AndroidRuntime(4151): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 09:50:52.177: E/AndroidRuntime(4151): at java.lang.reflect.Method.invoke(Method.java:507)
06-13 09:50:52.177: E/AndroidRuntime(4151): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-13 09:50:52.177: E/AndroidRuntime(4151): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-13 09:50:52.177: E/AndroidRuntime(4151): at dalvik.system.NativeStart.main(Native Method)
06-13 09:50:52.177: E/AndroidRuntime(4151): Caused by: java.lang.reflect.InvocationTargetException
06-13 09:50:52.177: E/AndroidRuntime(4151): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 09:50:52.177: E/AndroidRuntime(4151): at java.lang.reflect.Method.invoke(Method.java:507)
06-13 09:50:52.177: E/AndroidRuntime(4151): at android.view.View$1.onClick(View.java:2139)
06-13 09:50:52.177: E/AndroidRuntime(4151): ... 11 more
06-13 09:50:52.177: E/AndroidRuntime(4151): Caused by: java.lang.NullPointerException
06-13 09:50:52.177: E/AndroidRuntime(4151): at br.com.horussoft.vendas.NovaVendaActivity.Salvar_Click(NovaVendaActivity.java:56)
06-13 09:50:52.177: E/AndroidRuntime(4151): ... 14 more



4 Respostas


Ola Luciano

faça q nem este site aqui.....
http://rlsystem.com.br/forum/android/746-erro-com-location#top




Novo erro no logcat.

06-16 09:35:17.186: D/dalvikvm(10011): GC_EXTERNAL_ALLOC freed 101K, 46% free 2979K/5447K, external 503K/517K, paused 142ms
06-16 09:35:19.928: D/dalvikvm(10011): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
06-16 09:35:19.928: W/dalvikvm(10011): VFY: unable to resolve instance field 39
06-16 09:35:19.928: D/dalvikvm(10011): VFY: replacing opcode 0x52 at 0x0012
06-16 09:35:19.928: D/dalvikvm(10011): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
06-16 09:35:19.975: W/dalvikvm(10011): VFY: unable to resolve virtual method 23: Landroid/app/Activity;.getFragmentManager ()Landroid/app/FragmentManager;
06-16 09:35:19.975: D/dalvikvm(10011): VFY: replacing opcode 0x6e at 0x0023
06-16 09:35:19.975: D/dalvikvm(10011): VFY: dead code 0x0026-0030 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.showErrorDialogFragment (ILandroid/app/Activity;ILandroid/content/DialogInterface$OnCancelListener;)Z
06-16 09:35:20.084: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.084: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.092: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.108: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.311: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.319: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.342: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.389: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.600: D/dalvikvm(10011): GC_CONCURRENT freed 202K, 46% free 3063K/5639K, external 707K/1056K, paused 91ms 95ms
06-16 09:35:20.600: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.663: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.663: W/GooglePlayServicesUtil(10011): Google Play services out of date. Requires 4452000 but found 4325010
06-16 09:35:20.686: D/AndroidRuntime(10011): Shutting down VM
06-16 09:35:20.686: W/dalvikvm(10011): threadid=1: thread exiting with uncaught exception (group=0x40018578)
06-16 09:35:20.694: E/AndroidRuntime(10011): FATAL EXCEPTION: main
06-16 09:35:20.694: E/AndroidRuntime(10011): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.horussoft.vendas/br.com.horussoft.vendas.MapShowActivity}: java.lang.NullPointerException
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.os.Looper.loop(Looper.java:130)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-16 09:35:20.694: E/AndroidRuntime(10011): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 09:35:20.694: E/AndroidRuntime(10011): at java.lang.reflect.Method.invoke(Method.java:507)
06-16 09:35:20.694: E/AndroidRuntime(10011): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-16 09:35:20.694: E/AndroidRuntime(10011): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-16 09:35:20.694: E/AndroidRuntime(10011): at dalvik.system.NativeStart.main(Native Method)
06-16 09:35:20.694: E/AndroidRuntime(10011): Caused by: java.lang.NullPointerException
06-16 09:35:20.694: E/AndroidRuntime(10011): at br.com.horussoft.vendas.MapShowActivity.onCreate(MapShowActivity.java:31)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-16 09:35:20.694: E/AndroidRuntime(10011): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-16 09:35:20.694: E/AndroidRuntime(10011): ... 11 more

O google play não está desatualizado. Está tudo ok na instalação.
Não funciona o google maps nem a pau.




Este é o código:


package br.com.horussoft.vendas;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

public class NovaVendaActivity extends Activity implements LocationListener {
private double la;
private double lo;
LocationManager locationManager = null;
ProgressDialog pgd = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nova_venda);

Spinner spProdutos = (Spinner) findViewById(R.id.spProdutos);
SQLiteDatabase db = openOrCreateDatabase("vendas.db",
Context.MODE_PRIVATE, null);

Cursor cursor = db.rawQuery("SELECT * FROM produtos ORDER BY nome ASC",
null);

String[] from = { "_id", "nome", "preco" };

int[] to = { R.id.txVId, R.id.txVNome, R.id.txVPreco };

SimpleCursorAdapter ad = new SimpleCursorAdapter(getBaseContext(),
R.layout.spinner, cursor, from, to);

spProdutos.setAdapter(ad);

db.close();
}

@SuppressWarnings("unused")
@SuppressLint("NewApi")
public void Salvar_Click(View view) {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria(); // tipos de provider de acesso ao
String provider = locationManager.getBestProvider(criteria, false);
locationManager.requestLocationUpdates(provider, 1000, 0, this);

pgd = ProgressDialog.show(NovaVendaActivity.this, "Aguarde...",
"Buscando por Localização", true, false, null);

}

@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
pgd.dismiss();
la = location.getLatitude();
lo = location.getLongitude();

SQLiteDatabase db = openOrCreateDatabase("vendas.db",
Context.MODE_PRIVATE, null);

Spinner spProdutos = (Spinner) findViewById(R.id.spProdutos);
SQLiteCursor dados = (SQLiteCursor) spProdutos.getAdapter().getItem(
spProdutos.getSelectedItemPosition());

ContentValues ctv = new ContentValues();
ctv.put("produto", dados.getInt(0));
ctv.put("preco", dados.getDouble(2));
ctv.put("la", la);
ctv.put("lo", lo);

if (db.insert("vendas", "_id", ctv) > 0) {
Toast.makeText(getBaseContext(), "Sucesso!", Toast.LENGTH_LONG)
.show();
Toast.makeText(getBaseContext(), ctv.toString(), Toast.LENGTH_LONG)
.show();
}
db.close();
locationManager.removeUpdates(this);
}

@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(),
"Ative o GPS ou se conecte a Internet!", Toast.LENGTH_LONG)
.show();
}

@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub

}
}




Ola Luciano

veja esse topico aki

http://rlsystem.com.br/forum/android/788-curso-de-android-google-maps-nao-funciona#top