I am currently having trouble with call recording. The problem is with the AudioSouce because when i put MIC it works. Witch AudioSource option REALLY records calls.
Code:
Code:
if (i == REC) {
try {
if (isCall == false) {
Toast.makeText(context, "Not in a call", Toast.LENGTH_SHORT)
.show();
return;
}
if (IsRec == true) {
Toast.makeText(context, "Already recording",
Toast.LENGTH_SHORT).show();
return;
}
o = new File(Environment.getExternalStorageDirectory(),
"/recordings/"
+ new SimpleDateFormat("dd.MM.yyyy hh-mm-ss")
.format(new Date()) + ".amr");
r = new MediaRecorder();
r.setOutputFile(o.getAbsolutePath());
r.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); // HERE
r.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
r.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
r.prepare();
r.start();
IsRec = true;
Toast.makeText(context,
"Saving to: " + o.getAbsolutePath(),
Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
o = null;
r = null;
IsRec = false;
Log.e("Error", e.getMessage(), e.getCause());
Toast.makeText(context, "StateE: " + e.getMessage(),
Toast.LENGTH_LONG).show();
} catch (IOException e) {
o = null;
r = null;
IsRec = false;
Log.e("Error", e.getMessage(), e.getCause());
Toast.makeText(context, "IOE" + e.getMessage(),
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
o = null;
r = null;
IsRec = false;
e.printStackTrace();
Log.e("Error", e.getLocalizedMessage(), e.getCause());
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG)
.show();
}
}
LogCat:
Code:
07-18 10:17:18.850: E/MediaRecorder(607): start failed: -2147483648
07-18 10:17:18.859: W/System.err(607): java.lang.RuntimeException: start failed.
07-18 10:17:18.870: W/System.err(607): at android.media.MediaRecorder.start(Native Method)
07-18 10:17:18.880: W/System.err(607): at com.android.recorder.Widget.onReceive(Widget.java:137)
07-18 10:17:18.890: W/System.err(607): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2229)
07-18 10:17:18.890: W/System.err(607): at android.app.ActivityThread.access$1500(ActivityThread.java:130)
07-18 10:17:18.900: W/System.err(607): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
07-18 10:17:18.919: W/System.err(607): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 10:17:18.919: W/System.err(607): at android.os.Looper.loop(Looper.java:137)
07-18 10:17:18.940: W/System.err(607): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-18 10:17:18.950: W/System.err(607): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 10:17:18.960: W/System.err(607): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 10:17:18.969: W/System.err(607): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-18 10:17:18.980: W/System.err(607): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-18 10:17:18.990: W/System.err(607): at dalvik.system.NativeStart.main(Native Method)
07-18 10:17:18.999: E/Error(607): start failed.
Related
Hi Guys!
I'm coding a little app, but I don't know what I'm doing wrong.
The App does the following:
- Launches a Service which listens for an sms, then captures a picture with the cam and sends it to a predefined email adress. (no, i'm not trying to spy somebody out... I'm using the app to get a "3G-Webcam", sort of at least)
The problem:
My App works great in the emulator, but as soon as I try it on my HTC Magic (cm6, android 2.2) it stops working.
logcat:
10-28 19:05:31.190: DEBUG/QualcommCameraHardware(91): createInstance: E
10-28 19:05:31.599: DEBUG/QualcommCameraHardware(91): createInstance: X created hardware=0x3bac0
10-28 19:05:31.719: ERROR/QualcommCameraHardware(91): native_set_dimension: length: 28.
10-28 19:05:31.769: DEBUG/QualcommCameraHardware(91): snapshot_thread E
10-28 19:05:35.939: DEBUG/skia(26561): purging 114K from font cache [11 entries]
10-28 19:05:36.270: DEBUG/dalvikvm(26561): JIT code cache reset in 2 ms (524208 bytes 1/0)
10-28 19:05:36.270: DEBUG/dalvikvm(26561): GC_EXPLICIT freed 15951 objects / 694856 bytes in 329ms
10-28 19:05:36.770: ERROR/QualcommCameraHardware(91): native_get_picture: MSM_CAM_IOCTL_GET_PICTURE fd 18 error Connection timed out
10-28 19:05:36.770: ERROR/QualcommCameraHardware(91): getPicture failed!
10-28 19:05:36.770: DEBUG/QualcommCameraHardware(91): snapshot_thread X
The permissions are all set, even the write to SD-card. What am I missing?
Note: I'm not using a surfaceview.
Code:
public void takePictureAndSendByMail() {
new Task().execute();
}
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
File storagepath = Environment.getExternalStorageDirectory();
filename = String.format(storagepath + "/%d.jpg", System.currentTimeMillis());
outStream = new FileOutputStream(filename);
outStream.write(data);
outStream.close();
Log.d("E", "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d("E", "onPictureTaken - jpeg");
mCamera.release();
}
};
private class Task extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
mCamera = Camera.open();
Camera.Parameters parameters = mCamera.getParameters();
mCamera.setParameters(parameters);
}
protected Void doInBackground(Void... unused) {
try {
mCamera.takePicture(null, null, jpegCallback);
} catch (Exception e) {
Log.v("Error: ", "Exception", e);
}
return null;
}
protected void onPostExecute(Void unused) {
}
}
Click to expand...
Click to collapse
Hello, I want to download a xml file in local storage that I will parse.
The code is this
URL website = new URL("http://juventus.com/rss/news/ita.xml");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(c.getFilesDir()+"/eng.xml");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
This is called in doInBackground() of a AsyncTask class.
I get this error:
08-01 22:17:40.061: E/AndroidRuntime(9002): java.lang.RuntimeException: An error occured while executing doInBackground()
08-01 22:17:40.061: E/AndroidRuntime(9002): Caused by: java.lang.IllegalArgumentException: position=0 count=9223372036854775807
08-01 22:17:40.061: E/AndroidRuntime(9002): at java.nio.FileChannelImpl.transferFrom(FileChannelImpl.java:359)
What I do wrong?
I also tried this:
URL website = new URL("http://juventus.com/rss/news/ita.xml");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = c.openFileOutput("eng.xml", Context.MODE_PRIVATE);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
Hope you help me.
Thanks!
Try this...
Code:
URLConnection conn;
Log.d(TAG, "onDownload....path is: " + path);
try {
URL url = new URL(path);
conn = url.openConnection();
contentLength = conn.getContentLength();
DataInputStream in = new DataInputStream(conn.getInputStream());
Log.d(TAG, "Buffering the received stream(size=" + contentLength);
if (contentLength != -1) {
buffer = new byte[contentLength];
in.readFully(buffer);
in.close();
}else{
result = false;
return;
}
if (buffer.length > 0) {
Log.d(TAG,
"onDownload. Writing file to files dir,");
DataOutputStream out;
FileOutputStream fos = context.openFileOutput(fileName,
Context.MODE_PRIVATE);
Log.d(TAG, "Writing from buffer to the new file.." + fileName);
out = new DataOutputStream(fos);
out.write(buffer);
out.flush();
out.close();
result = true;
Edit: Here I am returning a boolean to indicate successful download.
Hello all,
I am trying to implement Google Cloud Messaging in my app, but I get the error java.io.IOException: AUTHENTICATION_FAILED when I test it on the device. Everything goes well on an Android 4 device, but I have two Android 2.3.3 devices (Samsung Galaxy II) and it fails every time.
From online search I learned that the error is/used to be because of a password problem or having multiple Google account installed. I checked the password and it's correct. It's true that the two devices tested had two Google accounts installed on each, but I uninstalled one and tried again but it failed again.
Anyone has any idea what could cause the problem?
The code that fails:
Code:
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regId = null;
try {
[B]regId = gcm.register(params[0]);[/B]
setRegistrationId(context, regId);
sendRegistrationToServer(regId);
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Registration failed. " + e);
e.printStackTrace();
}
The code is inside an AsyncTask. (Full code:
Code:
static public class BaseRegisterTask extends AsyncTask<String, Void, String> {
protected Context context = null;
BaseRegisterTask(Context context) {
this.context = context;
}
[user=439709]@override[/user]
protected String doInBackground(String... params) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regId = null;
try {
regId = gcm.register(params[0]);
setRegistrationId(context, regId);
sendRegistrationToServer(regId);
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Registration failed. " + e);
e.printStackTrace();
}
return regId;
}
protected void sendRegistrationToServer (String regId) {
// OVERRIDE ME
}
protected void onError(IOException e) {
Log.e(getClass().getSimpleName(), "Exception registering for GCM: ", e);
}
}
)
The caller:
Code:
new RegisterTask(getBaseContext()).execute(MESSAGING_SERVER_ID);
@ onCreate of the main activity.
The log:
Code:
10-04 13:25:37.238: E/RegisterTask(4057): Registration failed. java.io.IOException: AUTHENTICATION_FAILED
10-04 13:25:37.253: W/System.err(4057): java.io.IOException: AUTHENTICATION_FAILED
10-04 13:25:37.421: W/System.err(4057): at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
10-04 13:25:37.421: W/System.err(4057): at com.app.pushnotification.GCMRegistrarCompat$BaseRegisterTask.doInBackground(GCMRegistrarCompat.java:170)
10-04 13:25:37.421: W/System.err(4057): at com.app.pushnotification.GCMRegistrarCompat$BaseRegisterTask.doInBackground(GCMRegistrarCompat.java:1)
10-04 13:25:37.421: W/System.err(4057): at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-04 13:25:37.421: W/System.err(4057): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
10-04 13:25:37.421: W/System.err(4057): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
10-04 13:25:37.421: W/System.err(4057): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
10-04 13:25:37.421: W/System.err(4057): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
10-04 13:25:37.421: W/System.err(4057): at java.lang.Thread.run(Thread.java:1019)
Thank you in advance!
did you remove the Google account which had Access to the playstore or the other one?
mynote said:
did you remove the Google account which had Access to the playstore or the other one?
Click to expand...
Click to collapse
I removed the other one. The device doesn't let me remove the one associated with the Play Store. (The error message says that to do that, one has to perform factory reset...)
I tried switching the Play Store account to the other one, but it still fails with the same error [and the other account is still non-removable.
Hello everyone, me again.
I am having a little issue with my android app.
When I run the service on the phone, it starts just fine and when the call is disconnected it throws an java.lang.NullPointerException when i start the tareaEnviarABD.execute(); task.
This is the code of my service:
Code:
package com.trucka.llamadasdrivers;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.IBinder;
import android.provider.CallLog;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
public class ServicioLlamadas extends Service {
TextView txtInformacion = null;
TextView txtDetalles = null;
TextView tv = null;
private String resultado;
String phNumber = null;
String callType = null;
String callDate = null;
DateFormat shortFecha = null;
DateFormat shortDF = null;
Date callDayTime = null;
Date fin = null;
String fechaLlamada1 = null;
String fechaLlamada2 = null;
String callDuration = null;
String dir = null;
public String tolo = null;
String imei = null;
String comentario = null;
String fechaRegistro = null;
String insercion = null;
String fechaInicio = null;
String fechaFin = null;
String estadoLlamada = null;
private static ServicioLlamadas instance = null;
public static boolean isRunning() {
return instance != null;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(getApplicationContext(), "Servicio TRUCKA creado",
Toast.LENGTH_SHORT).show();
instance = this;
}
@Override
public void onDestroy() {
Toast.makeText(getApplicationContext(), "Servicio TRUCKA destruído",
Toast.LENGTH_SHORT).show();
instance = null;
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(getApplicationContext(), "Servicio TRUCKA iniciado",
Toast.LENGTH_SHORT).show();
TelephonyManager TelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
TelephonyMgr.listen(new TeleListener(),
PhoneStateListener.LISTEN_CALL_STATE);
}
class TeleListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
if (estadoLlamada == "OFFHOOK") {
insercion = null;
getCallDetails();
Toast.makeText(getApplicationContext(),
"Información enviada.", Toast.LENGTH_SHORT).show();
}
estadoLlamada = "IDLE";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
estadoLlamada = "OFFHOOK";
Toast.makeText(getApplicationContext(),
"Enviando información...", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
break;
default:
break;
}
}
}
//Obtener la fecha actual del teléfono.
public long getTodayTimestamp() {
Calendar c1 = Calendar.getInstance();
c1.setTime(new Date());
Calendar c2 = Calendar.getInstance();
c2.set(Calendar.YEAR, c1.get(Calendar.YEAR));
c2.set(Calendar.MONTH, c1.get(Calendar.MONTH));
c2.set(Calendar.DAY_OF_MONTH, c1.get(Calendar.DAY_OF_MONTH));
c2.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.SECOND, 0);
return c2.getTimeInMillis();
}
private void getCallDetails() {
String timestamp = String.valueOf(getTodayTimestamp());
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
CallLog.Calls.DATE + ">= ?", new String[] { timestamp }, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Bitácora de llamadas :");
//managedCursor.moveToFirst();
managedCursor.moveToLast();
phNumber = managedCursor.getString(number);
callType = managedCursor.getString(type);
callDate = managedCursor.getString(date);
shortFecha = DateFormat.getDateInstance(DateFormat.SHORT);
shortDF = DateFormat.getTimeInstance(DateFormat.SHORT);
callDayTime = new Date(Long.valueOf(callDate));
fechaLlamada1 = shortDF.format(callDayTime);
fechaLlamada2 = shortFecha.format(callDayTime);
callDuration = managedCursor.getString(duration);
int dircode = Integer.parseInt(callType);
TelephonyManager mngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "Saliente";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "Entrante";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "Perdida";
break;
}
imei = mngr.getDeviceId();
comentario = dir;
fechaRegistro = fechaLlamada2;
DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
String ahorita = df.format(callDayTime);
fechaInicio = ahorita.toString();
insercion = "DECLARE @claveDriver INT, @nombreDriver VARCHAR(max), @evento VARCHAR(max), @duracion int, @inicial varchar(max) "
+ "SET @claveDriver = (SELECT cve_tra FROM SISTEMA.dbo.TELEFONOS WHERE IMEI_SIM = '"
+ mngr.getDeviceId()
+ "') "
+ "SET @nombreDriver = (SELECT nombre FROM SISTEMA.dbo.TELEFONOS WHERE IMEI_SIM = '"
+ mngr.getDeviceId()
+ "') "
+ "SET @duracion = "
+ managedCursor.getString(duration)
+ "SET @evento = '(LOG) Llamada "
+ dir
+ ". Duración ' + CONVERT(varchar, @duracion, 103) + ' segundos al número: "
+ managedCursor.getString(number)
+ "' "
+ " SET @inicial = '"
+ fechaInicio
+ "'"
+ "INSERT INTO bitacora.dbo.registroDellamadasOperadores (fechacreacion,fecha_fin,fecha_inicio,idMobil,Tractor,Nom_tra,Cve_tra,FechaRegistro,Evento) "
+ " VALUES('"
+ fechaInicio
+ "', DATEADD(SECOND,@duracion,@inicial),'"
+ fechaInicio
+ "','"
+ mngr.getDeviceId()
+ "','',@nombreDriver,@claveDriver,current_timestamp,@evento)";
try
{
AsyncCallWS tareaEnviarABD = new AsyncCallWS();
tareaEnviarABD.execute();
}catch(Exception e){
Toast.makeText(getApplicationContext(),
e.toString(), Toast.LENGTH_SHORT).show();
}
}
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Log.i(TAG, "doInBackground");
InsertarLlamada(insercion);
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
txtInformacion.setText("Información enviada");
}
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
txtInformacion.setText("Enviando información...");
}
@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}
}
public void InsertarLlamada(String insercion) {
// Creamos la solicitud
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Propiedades que contienen los valores
PropertyInfo propiedades = new PropertyInfo();
propiedades.setName("insercion");
propiedades.setValue(insercion);
propiedades.setType(String.class);
// Agregamos las propiedades
request.addProperty(propiedades);
// Creamos el envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// ponemos la salida SOAP
envelope.setOutputSoapObject(request);
// Creamos la llamada HTTP
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invocamos el servicio
androidHttpTransport.call(SOAP_ACTION, envelope);
// Obtenemos la respuesta
Object response = envelope.getResponse();
// Asignamos el resultado de la consulta
resultado = response.toString();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
And the log cat shows this:
Code:
02-25 09:32:32.946: D/ActivityThread(8866): setTargetHeapUtilization:0.25
02-25 09:32:32.946: D/ActivityThread(8866): setTargetHeapIdealFree:8388608
02-25 09:32:32.946: D/ActivityThread(8866): setTargetHeapConcurrentStart:2097152
02-25 09:33:07.663: D/libEGL(8866): loaded /system/lib/egl/libEGL_adreno200.so
02-25 09:33:07.663: D/libEGL(8866): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
02-25 09:33:07.663: D/libEGL(8866): loaded /system/lib/egl/libGLESv2_adreno200.so
02-25 09:33:07.683: I/Adreno200-EGLSUB(8866): <ConfigWindowMatch:2087>: Format RGBA_8888.
02-25 09:33:07.693: E/(8866): <s3dReadConfigFile:75>: Can't open file for reading
02-25 09:33:07.693: E/(8866): <s3dReadConfigFile:75>: Can't open file for reading
02-25 09:33:07.693: D/OpenGLRenderer(8866): Enabling debug mode 0
02-25 09:33:13.128: I/TRUCKA_DRIVERS(8866): onPreExecute
02-25 09:33:13.128: D/AndroidRuntime(8866): Shutting down VM
02-25 09:33:13.128: W/dalvikvm(8866): threadid=1: thread exiting with uncaught exception (group=0x41e48438)
02-25 09:33:13.128: E/AndroidRuntime(8866): FATAL EXCEPTION: main
02-25 09:33:13.128: E/AndroidRuntime(8866): java.lang.NullPointerException
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.trucka.llamadasdrivers.ServicioLlamadas$AsyncCallWS.onPreExecute(ServicioLlamadas.java:239)
02-25 09:33:13.128: E/AndroidRuntime(8866): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
02-25 09:33:13.128: E/AndroidRuntime(8866): at android.os.AsyncTask.execute(AsyncTask.java:534)
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.trucka.llamadasdrivers.ServicioLlamadas.getCallDetails(ServicioLlamadas.java:215)
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.trucka.llamadasdrivers.ServicioLlamadas.access$0(ServicioLlamadas.java:143)
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.trucka.llamadasdrivers.ServicioLlamadas$TeleListener.onCallStateChanged(ServicioLlamadas.java:108)
02-25 09:33:13.128: E/AndroidRuntime(8866): at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:421)
02-25 09:33:13.128: E/AndroidRuntime(8866): at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 09:33:13.128: E/AndroidRuntime(8866): at android.os.Looper.loop(Looper.java:137)
02-25 09:33:13.128: E/AndroidRuntime(8866): at android.app.ActivityThread.main(ActivityThread.java:5062)
02-25 09:33:13.128: E/AndroidRuntime(8866): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 09:33:13.128: E/AndroidRuntime(8866): at java.lang.reflect.Method.invoke(Method.java:511)
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
02-25 09:33:13.128: E/AndroidRuntime(8866): at dalvik.system.NativeStart.main(Native Method)
02-25 09:33:14.240: I/Process(8866): Sending signal. PID: 8866 SIG: 9
Can someone please tell me what am I doing wrong?
Thanks!
FedePrado said:
Hello everyone, me again.
Code:
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
txtInformacion.setText("Enviando información...");
}
02-25 09:33:13.128: E/AndroidRuntime(8866): java.lang.NullPointerException
02-25 09:33:13.128: E/AndroidRuntime(8866): at com.trucka.llamadasdrivers.ServicioLlamadas$AsyncCallWS.onPreExecute(ServicioLlamadas.java:239)
Click to expand...
Click to collapse
it tells you there, note that on line 239 you are asking an object (in this case "txtInfromacion") to execute one of it's methods, but the object is actually "null" so it throws the exception
disclaimer, I only looked at it for 10 seconds cause busy but I would think there is a 99.5% chance I'm correct
EDIT : ok looked at it another 5 seconds, you never assign anything to that TextView, like associating it with the view on screen ? eg. findViewById(R.id.someID)
Hi, Dear XDA-developers,
Recently, I tried to build an blue tooth app. I wanted to display the data in the screen when all data arrived. I used the following code to do that job. However, the looping between Broadcaster receiver and Handler message could not be linked together smoothly. Usually, after one data displayed, I got an error with the following logs
02-03 05:01:30.931: W/dalvikvm(3419): threadid=11: thread exiting with uncaught exception (group=0x40018560)
02-03 05:01:37.827: E/AndroidRuntime(3419): FATAL EXCEPTION: Thread-13
02-03 05:01:37.827: E/AndroidRuntime(3419): java.lang.NullPointerException
02-03 05:01:37.827: E/AndroidRuntime(3419): at com.huasu.healthmonitor3.Device_Activity$1$2.run(Device_Activity.java:325)
02-03 05:01:37.827: E/AndroidRuntime(3419): at java.lang.Thread.run(Thread.java:1019)
the code snippet is as followings, any suggestions are appreciated!
public final Handler mHandler = new Handler() {
@override
public void handleMessage(Message msg) {
switch (msg.what) {
case Common.MESSAGE_CONNECT:
new Thread(new Runnable() {
public void run() {
InputStream tmpIn;
OutputStream tmpOut;
try {
UUID uuid = UUID.fromString(SPP_UUID);
BluetoothDevice btDev = btAdapt
.getRemoteDevice(strAddress);
btSocket = btDev
.createRfcommSocketToServiceRecord(uuid);
btSocket.connect();
tmpIn = btSocket.getInputStream();
tmpOut = btSocket.getOutputStream();
} catch (Exception e) {
Log.d(Common.TAG, "Error connected to: "
+ strAddress);
bConnect = false;
mmInStream = null;
mmOutStream = null;
btSocket = null;
e.printStackTrace();
mHandler.sendEmptyMessage(Common.MESSAGE_CONNECT_LOST);
return;
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
mHandler.sendEmptyMessage(Common.MESSAGE_CONNECT_SUCCEED);
}
}).start();
break;
case Common.MESSAGE_CONNECT_SUCCEED:
bConnect = true;
new Thread(new Runnable() {
public void run() {
// First write command to the bluetooth port
try{
mmOutStream.write(comm1);
}
catch (Exception e) {
Log.d(Common.TAG, "Error in writing command to bluetooth ");
}
int nRecv = 0;
while (bConnect) {
try {
Log.e(Common.TAG, "Start Recv" + String.valueOf(mmInStream.available()));
nRecv = mmInStream.read(bufRecv);
if (nRecv < 1) {
Log.e(Common.TAG, "Recving Short");
Thread.sleep(100);
continue;
}
System.arraycopy(bufRecv, 0, bRecv, nRecved, nRecv);
Log.e(Common.TAG, "Recv:" + String.valueOf(nRecv));
nRecved += nRecv;
if(nRecved < nNeed)
{
Thread.sleep(1000);
continue;
}
//sendBroadcast(intent);
mHandler.obtainMessage(Common.MESSAGE_RECV,nNeed, -1, null).sendToTarget();
} catch (Exception e) {
Log.e(Common.TAG, "Recv thread:" + e.getMessage());
mHandler.sendEmptyMessage(Common.MESSAGE_EXCEPTION_RECV);
break;
}
}
Log.e(Common.TAG, "Exit while");
}
}).start();
break;
case Common.MESSAGE_EXCEPTION_RECV:
case Common.MESSAGE_CONNECT_LOST:
try {
if (mmInStream != null)
mmInStream.close();
if (mmOutStream != null)
mmOutStream.close();
if (btSocket != null)
btSocket.close();
} catch (IOException e) {
Log.e(Common.TAG, "Close Error");
e.printStackTrace();
} finally {
mmInStream = null;
mmOutStream = null;
btSocket = null;
bConnect = false;
}
break;
case Common.MESSAGE_WRITE:
break;
case Common.MESSAGE_READ:
break;
case Common.MESSAGE_RECV:
Boolean bOn = false;
if(extr_validate_data())
{
bytesTofloat(bRec_out,3072);
broadcastIntent();
}
case Common.MESSAGE_TOAST:
Toast.makeText(getApplicationContext(),
msg.getData().getString(Common.TOAST),
Toast.LENGTH_SHORT).show();
break;
}
}
};
private BroadcastReceiver connectDevices = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(Common.TAG, "Receiver:" + action);
update_dis();
mHandler.obtainMessage(Common.MESSAGE_CONNECT_SUCCEED,nNeed, -1, null).sendToTarget();
}
};
public void broadcastIntent()
{
Intent intent = new Intent();
intent.setAction("com.huasu.healthmonitor3.draw");
sendBroadcast(intent);
}
It seems that the problematic part is in the Device_Activity.java at line 325. Could you post that line and lines around it here?