Cancel Button on a Sub-activity got a RuntimeException

Put your problem here if it does not fit any of the other categories.

Cancel Button on a Sub-activity got a RuntimeException

Postby cyberrob » Tue Feb 19, 2008 3:15 am

Hi all,

Here I got a Sub-activity ,in which there are two buttons,one is OK button,the other is Cancel button.
In the Subactivity Class, the Cancel button implemented as follows

Code: Select all
cancel.setOnClickListener(new OnClickListener() {
         public void onClick(View arg0) {
            // Close this Activity
            MySubActivity.this.setResult(RESULT_CANCELED);
            MySubActivity.this.finish();
         }
      });


So when Cancel button been clicked, we got a RuntimeException:
Failure delivering result ResultInfo{who=null, request=1440, result=0, data=null, extras=null} to Original Activity: java.lang.NullPointerException

As far as I know, it seems that the cancel button didnt send back some arguments, which showed in ResultInfo, like who,result, data,extras. But Since the Cancel Button been CLICKed, why should send back the arguments?? OK, if follow the rules of API, what are needed and how to do this??

I got confused! Hope someone can HELP!! :cry:
Thanks!
User avatar
cyberrob
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Dec 13, 2007 3:01 am

Top

Postby plusminus » Tue Feb 19, 2008 6:12 pm

Hello cyberrob,

you only called setResult(...) the others (except requestcode) are null, because you did not call them.

The funny thing is why the Exception occurs. :?
Did you try running it after a -wipe-data :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby cyberrob » Wed Feb 20, 2008 3:41 am

My Run argument now is
Code: Select all
-sdcard d:sdcard.img -wipe-data

IT didnt change anything, and I also try just -wipe-data, result the same.

The key point is ,you said I only called setResult(), what else functions should I CALL??
Maybe in this page: android.app.Activity
Could u please point them out?
Thx :!:
BTW which exception let u feel funny? Runtime or Null? :lol:

plusminus wrote:Hello cyberrob,

you only called setResult(...) the others (except requestcode) are null, because you did not call them.

The funny thing is why the Exception occurs. :?
Did you try running it after a -wipe-data :?:

Regards,
plusminus
:!:
User avatar
cyberrob
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Dec 13, 2007 3:01 am

Postby plusminus » Wed Feb 20, 2008 10:47 am

Hello cyberrob,

its funny, because I'm doing exactly the same :darrow: and it works fine.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /* Set OnClickListener for Back-Button. */
  2.  
  3. findViewById(R.id.ibtn_sd_country_back).setOnClickListener(new OnClickListener(){
  4.  
  5.         @Override
  6.  
  7.         public void onClick(View v) {
  8.  
  9.                 /* Back one level. */
  10.  
  11.                 SDCountry.this.setResult(Constants.SUBACTIVITY_RESULTCODE_UP_ONE_LEVEL);
  12.  
  13.                 SDCountry.this.finish();
  14.  
  15.         }
  16.  
  17. });
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


:?

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 22 guests