Foro sobre Java SE > Location Listener, Datagramsocket ayuda!!!
Tendrás que ejecutar la aplicación desde el IDE en modo depuración para obtener la excepción completa y saber así qué excepción provoca la detención de la aplicación. Seguramente estás intentando usar una variable que no referencia ningún objeto y estás obteniendo un NullPointerException, pero no estoy seguro.
rickiees muchas gracias por tomarte el tiempo de ayudarme, si me ha servido he encontrado que el error esta es un java.lang.NullPointerException de una variable que no referencia ningun objeto que me recomiendas para resolverlo que paso debo seguir? muchas gracias por tu tiempo amigo!
Necesitamos tu traza de error completa para ver en que línea del código de el error.
Y esto debería de ir en el foro de Android no aquí.
aquí esta la traza del error y warnings, gracias
09-29 10:39:58.862: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:39:59.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:39:59.864: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:00.004: E/ActivityManager(586): Intent: Intent { act=android.intent.action.TIME_TICK flg=0x40000014 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:00.860: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:00.869: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:01.858: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:02.396: W/SignalStrength(754): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:02.397: W/SignalStrength(586): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:02.400: W/SignalStrength(689): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:02.405: W/SignalStrength(689): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:02.407: E/ActivityManager(586): Intent: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:02.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:02.868: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:03.823: E/ActivityManager(586): Intent: Intent { act=android.net.wifi.RSSI_CHANGED flg=0x8000010 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:03.829: W/asset(689): Asset path /data/theme/com.android.systemui is neither a directory nor file (type=1).
09-29 10:40:03.858: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:04.858: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:04.865: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:05.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:06.857: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:06.868: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:07.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:07.869: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:08.594: E/ActivityManager(586): Intent: Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000010 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:08.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:08.870: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:09.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:10.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:10.868: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:11.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:12.629: W/SignalStrength(754): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:12.630: W/SignalStrength(586): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:12.632: W/SignalStrength(689): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:12.639: W/SignalStrength(689): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:12.640: E/ActivityManager(586): Intent: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:12.857: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:12.863: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:13.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:13.865: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:14.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:15.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:15.864: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:16.858: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:17.750: W/SignalStrength(754): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:17.751: W/SignalStrength(586): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:17.754: W/SignalStrength(689): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:17.761: W/SignalStrength(689): getGsmLevel ro.show.3g.level.by.rscp = false
09-29 10:40:17.762: E/ActivityManager(586): Intent: Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:17.859: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
09-29 10:40:17.865: W/Provider/Settings(586): Setting auto_time_gps has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
09-29 10:40:18.594: E/ActivityManager(586): Intent: Intent { act=android.intent.action.BATTERY_CHANGED flg=0x60000010 (has extras) }mEnablePowerSaverManagerFunction:truesuperMode:false
09-29 10:40:18.860: E/mnl_linux(13262): mtk_gps_sys_gps_mnl_callback: Get SV info success
Eso no es un stacktrace de JavaSE.
Ya te han pedido que publiques tu cuestión en el foro apropiado: Android.
Mi consejo:
Vete la foro de Android y publica de nuevo la pregunta pon la siguiente información:
1 - Arranca la aplicación me modo debug y pruebala.
2 - Explica bien lo que te pasa...por ejemplo "Aranco la apliación y al pinchar en tal botón da el siguiente error."....etc..
3 - Al arracar en modo debug la consola del eclipse o la de Android (logcat) tiene que mostrar el error que te ha salido.
4 - pon el código para que comprobemos el error.
Y así sí seremos capaces de ayudarte
Un saludo
respetados señores del foro un cordial saludo la presente es para pedirle ayuda primera vez que me toca trabajar con java en la carrera y llevo una semana tratando de que esto me dé, trato de hacer una aplicación para android en eclipse que reciba las coordenadas las muestre y a su vez las mande por UDP a un servidor IP/Port tengo el código de abajo, la app abre pero cuando las coordenadas empiezan a cambiar se cierra y dice que la aplicación se detuvo.
Le agradezco lo que me puedan corregir del código. A todos Muchas gracias feliz fin de semana.
Código java:
package diseno.gpsdiseno;
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.view.Menu;
import android.widget.TextView;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import android.util.Log;
import java.text.DecimalFormat;
import java.util.Date;
import android.widget.EditText;
public class MainActivity extends Activity {
TextView miTexto1, miTexto2;
private DatagramSocket datagramSocket;
private String destination_host;
private int destination_port;
private EditText editTextPort;
private EditText editTextHost;
private static final DecimalFormat decimal_format = new DecimalFormat("000.0000000");
private void FindViews()
{
this.editTextHost = ((EditText)findViewById(R.id.editText1));
this.editTextPort = ((EditText)findViewById(R.id.editText2));
}
private void SendMessageByUdp(String paramString)
{
try
{
this.destination_host = this.editTextHost.getEditableText().toString();
this.destination_port = Integer.parseInt(this.editTextPort.getEditableText().toString());
byte[] arrayOfByte = paramString.getBytes();
InetAddress localInetAddress = InetAddress.getByName(this.destination_host);
DatagramPacket localDatagramPacket = new DatagramPacket(arrayOfByte, arrayOfByte.length, localInetAddress, this.destination_port);
if (this.datagramSocket == null) {
this.datagramSocket = new DatagramSocket();
}
this.datagramSocket.send(localDatagramPacket);
return;
}
catch (IOException localIOException)
{
this.datagramSocket = null;
Log.v("SensorUdp#SendDebugMessageByUdp", localIOException.toString());
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
miTexto1 = (TextView)findViewById(R.id.textView1);
miTexto2 = (TextView)findViewById(R.id.textView2);
LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final Location localizacion = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (localizacion != null){
miTexto1.setText("Latitud: " + String.valueOf(localizacion.getLatitude()));
miTexto2.setText("Longitud: " + String.valueOf(localizacion.getLongitude()));
} else {
miTexto1.setText("Sin datos de latitud.");
miTexto2.setText("Sin datos de longitud.");
}
LocationListener locListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location localizacion) {
miTexto1.setText("Latitud: " + String.valueOf(localizacion.getLatitude()));
miTexto2.setText("Longitud: " + String.valueOf(localizacion.getLongitude()));
Date localDate1 = new Date();
String str1 = localDate1.getTime() + ", " + decimal_format.format(localizacion.getAltitude()) + ", " + decimal_format.format(localizacion.getLatitude()) + ", " + decimal_format.format(localizacion.getLongitude()) + ", " + localizacion.getTime() + ", " + decimal_format.format(localizacion.getAccuracy()) + ", " + decimal_format.format(localizacion.getSpeed()) + "\n";
SendMessageByUdp(str1);
}
};
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locListener);
}
@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;
}
}
----------------------------------------------------------------------------------
android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="diseno.gpsdiseno"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.SET_DEBUG_APP"/>
<category android:name="android.intent.category.LAUNCHER" />
</manifest>