i can't send email in UncaughtExceptionHandler for Service

by codefish » Thu, 22 Jul 2010 11:48:02 GMT


Sponsored Links
 i want to handle exceptions in Service.
my exception handler sends error report email.
so i add FLAG_ACTIVITY_NEW_TASK flag and it works fine in onCreate().
but in UncaughtExceptionHandler, it doesn't send email.

so how it can send email in uncaughtException()?

public class ErrorReporter implements Thread.UncaughtExceptionHandler
{
  //....
  public void uncaughtException(Thread t, Throwable e) {
    // ...
    SendErrorMail(this.CurContext, Report);
  }

  private void SendErrorMail(Context _context, String ErrorContent) {
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        String subject = ("Crash Report - Android ErrorReporter");
        String body = ErrorContent + "\n\n";
        sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]
{"92soc...@gmail.com"});
        sendIntent.putExtra(Intent.EXTRA_TEXT, body);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        sendIntent.setType("message/rfc822");
        Intent i = Intent.createChooser(sendIntent, "Title:");
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  // because
Service ...
        _context.startActivity(i);
  }
}

thank you

--



i can't send email in UncaughtExceptionHandler for Service

by DanH » Thu, 22 Jul 2010 20:40:59 GMT


 First off, are you sure that your UncaughtExceptionHandler is not
throwing an exception?




--


Sponsored Links


i can't send email in UncaughtExceptionHandler for Service

by Joseph Earl » Fri, 23 Jul 2010 03:30:39 GMT


 You email is not getting sent because you are not doing anything with
your sendIntent. You create it but then never use it.



--



i can't send email in UncaughtExceptionHandler for Service

by Joseph Earl » Fri, 23 Jul 2010 03:34:33 GMT


 Scratch that. My mistake. I missed the Intent.createChooser line.
Have you taken a look at: 
 http://www.anddev.org/email_send_intent_intentchooser-t3295.html 
?

I don't see any immediate errors in your code.





--



i can't send email in UncaughtExceptionHandler for Service

by codefish » Thu, 29 Jul 2010 19:45:45 GMT


 thank you for your reply
I added try/catch code but I got no exception
and it still doesn't send a email ;(

        try
        {
            _context.startActivity(i);
            Log.d(LOG_TAG, "startActivity() called");
        } catch (Exception e)
        {
            e.printStackTrace();
        }

below is my logcat log

WARN/dalvikvm(582): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
DEBUG/ErrorReporter(582): uncaughtException() tThread[main,5,main],
except:java.lang.RuntimeException: Unable to create service
com.my.service: java.lang.NullPointerException
INFO/ActivityManager(53): Starting activity: Intent
{ act=android.intent.action.CHOOSER flg=0x10000000 cmp=android/
com.android.internal.app.ChooserActivity (has extras) }
DEBUG/ErrorReporter(582): startActivity() called
ERROR/AndroidRuntime(582): Uncaught handler: thread main exiting due
to uncaught exception
ERROR/AndroidRuntime(582): java.lang.RuntimeException: Unable to
create service com.my.service: java.lang.NullPointerException
ERROR/AndroidRuntime(582):     at
android.app.ActivityThread.handleCreateService(ActivityThread.java:
2790)
ERROR/AndroidRuntime(582):     at android.app.ActivityThread.access
$3200(ActivityThread.java:119)
ERROR/AndroidRuntime(582):     at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1917)
ERROR/AndroidRuntime(582):     at
android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(582):     at android.os.Looper.loop(Looper.java:
123)
ERROR/AndroidRuntime(582):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
ERROR/AndroidRuntime(582):     at
java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(582):     at
java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(582):     at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
ERROR/AndroidRuntime(582):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
ERROR/AndroidRuntime(582):     at
dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(582): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(582):     at
com.my.service.onCreate(ISPService.java:230)
ERROR/AndroidRuntime(582):     at
android.app.ActivityThread.handleCreateService(ActivityThread.java:
2780)
ERROR/AndroidRuntime(582):     ... 10 more
INFO/Process(53): Sending signal. PID: 582 SIG: 3
INFO/dalvikvm(582): threadid=7: reacting to signal 3
INFO/dalvikvm(582): Wrote stack trace to '/data/anr/traces.txt'

I can't know why.

--



i can't send email in UncaughtExceptionHandler for Service

by Joseph Earl » Thu, 29 Jul 2010 20:06:51 GMT


 Here's your error:

java.lang.NullPointerException at
com.my.service.onCreate(ISPService.java line:230)

Take a look at line 230 of ISPService.java and try and see what could
possibly be null.




--



Other Threads

1. Computation on db data then list them using either SimpleCursorAdapter or ArrayAdapter

Hi all,

I juststarted programming in android a few weeks ago, so I am not
entirely sure how to deal with listing values. Please help me out!
I have some questions regarding displaying data sets from db in a
list. Currently I have a cursor returned by my db points to a list of
rows and I want display 2 columns values in a single row of the list.
The row xml looks like this:

     <TextView android:id="@+id/text1"
         android:textSize="16sp"
         android:textStyle="bold"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"/>

     <TextView android:id="@+id/text2"
         android:textSize="14sp"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"/>

so I was thinking using simplecursoradapter which supposedly makes my
life easier by displaying the data in a list. However that is only
true if I want to display the raw data.
For the purpose of my program I need to do some computations on the
raw data sets, then display them. I am not sure how to do that using
SimpleCursorAdapter. Here's how I display the raw data:

       String[] from = new String[]
{BtDbAdapter.KEY_EX_TYPE,BtDbAdapter.KEY_EX_TIMESTAMP};

       int[] to = new int[]{R.id.text1, R.id.text2};

        // Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter records =
                    new SimpleCursorAdapter(this, R.layout.exset_row,
mExsetCursor, from, to);

        setListAdapter(records);

Is there a way to do computation on the data in those rows before I
bind it with the SimpleCursorAdapter? I was trying to use an
alternative way of doing this by using arraylist and arrayadapter, but
that way I dont know to how achieve displaying 2 items in a single
row.

This is my code for using arrayadapter which only display 1 text in a
row instead of 2 textviews in a row:

      //fill in the array
      timestamp_arr = new ArrayList<String>();
      type_arr = new ArrayList<String>();
      fillRecord();

      Log.d(TAG,"setting now in recordlist");
          setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_item,timestamp_arr));
          setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_item2,type_arr));

It's very obvious that it only displays one textview in a row because
I set the second arrayadapter overwrites the first one! I was trying
to use R.id.text1 and R.id.text2 for them, but it gave me some errors
saying
04-23 01:40:58.658: ERROR/AndroidRuntime(3309):
android.content.res.Resources$NotFoundException: Resource ID
#0x7f070008 type #0x12 is not valid

I believe the second method can achieve this, but I'm not sure how do
deal with the layout problems, so if you any suggestions, please post
them out. Thank you!!

-- 

2. HTC beli palm, akankah tinggalkan android?

http://www.engadget.com/2010/04/23/htc-decides-against-bidding-for-palm-kills-our-buzz/

---
Regards,
Ibnu Ibrahim

-- 
"Indonesian Android Community [id-android]" 

3. (WTI) promo gt+mega diskon 500 rb+cicilan 0% 12 bln for Spica

4. BroadcastReceiver dilemma

5. How to change preference text color

6. hapus apk bwaan & upgrade firmware hh android

7. Change color of progressbar