Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8597567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:56:32+00:00 2026-06-12T00:56:32+00:00

Here’s a section of my code : @Override public boolean onOptionsItemSelected(MenuItem item) { switch

  • 0

Here’s a section of my code :

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.menu_settings:

        startActivityForResult(new Intent(MainActivity.this,Settings.class),1);
        break;
    }
    return true;
}


@Override
public void onActivityResult(int requestCode,int resultCode,Intent data) {

    Toast.makeText(getBaseContext(),requestCode, Toast.LENGTH_SHORT); // This was causing the error. See the fantastic answer that's been provided for details. Comment out this this and it works !

    if(requestCode==1) {
        if(resultCode==RESULT_OK) 
        {
            String extraData=data.getData().toString();

            minD=Integer.parseInt(extraData);
            Toast.makeText(getBaseContext(),minD, Toast.LENGTH_SHORT);
        }

    }

}

Here’s the code for Settings.java

package com.example.com.draft1;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;



public class Settings extends Activity  {



@Override 

public void onCreate(Bundle savedInstanceState)
{

    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);


    Button setbtn = (Button) findViewById(R.id.SetminDistance);


    setbtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

        //Intent data=new Intent();
        EditText mind=(EditText) findViewById(R.id.minDistance);
                    String minDis =mind.getText().toString();
                    Intent data = new Intent();   
                    data.setData(Uri.parse(minDis));

        Toast.makeText(getBaseContext(), minDis, Toast.LENGTH_SHORT).show();
                  //  intent.putExtra("minD", minDis);





       if (getParent() == null) {
           setResult(RESULT_OK, data);
       } else {
           getParent().setResult(RESULT_OK, data);
       }
       finish();



      /*  setResult(RESULT_OK, data);
       finish();*/
            }

});

}
}

Now when I choose the menu option for Settings , the required activity opens up perfectly , however , when i attempt to return data , it leads to a force close

Here’s the Logcat reading that shows the error :

09-29 16:03:29.366: E/AndroidRuntime(766): FATAL EXCEPTION: main
09-29 16:03:29.366: E/AndroidRuntime(766): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=65 }} to activity {com.example.com.draft1/com.example.com.draft1.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x1
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.ActivityThread.access$2000(ActivityThread.java:117)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.os.Looper.loop(Looper.java:130)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-29 16:03:29.366: E/AndroidRuntime(766):  at java.lang.reflect.Method.invokeNative(Native Method)
09-29 16:03:29.366: E/AndroidRuntime(766):  at java.lang.reflect.Method.invoke(Method.java:507)
09-29 16:03:29.366: E/AndroidRuntime(766):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-29 16:03:29.366: E/AndroidRuntime(766):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-29 16:03:29.366: E/AndroidRuntime(766):  at dalvik.system.NativeStart.main(Native Method)
09-29 16:03:29.366: E/AndroidRuntime(766): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.content.res.Resources.getText(Resources.java:201)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.widget.Toast.makeText(Toast.java:258)
09-29 16:03:29.366: E/AndroidRuntime(766):  at com.example.com.draft1.MainActivity.onActivityResult(MainActivity.java:570)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.Activity.dispatchActivityResult(Activity.java:3908)
09-29 16:03:29.366: E/AndroidRuntime(766):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
09-29 16:03:29.366: E/AndroidRuntime(766):  ... 11 more

Why am i encountering a force close here ?

I’d really appreciate help here

Thanks for the interest in the question

As Per Suggestions

if(requestCode==1) {
        if(resultCode==RESULT_OK) 
        {
            //String extraData=data.getData().toString();

            //minD=Integer.parseInt(extraData);
            Toast.makeText(getBaseContext(),String.valueOf(requestCode), Toast.LENGTH_SHORT).show();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:56:33+00:00Added an answer on June 12, 2026 at 12:56 am

    If you see Toast.makeText

    public static Toast makeText (Context context, int resId, int duration)
    

    So if you giving second parameter as int then system will look for this id in R.java but irony is actually you wanting to print number so just cast your second parameter to String i.e. this

    public static Toast makeText (Context context, CharSequence text, int duration)
    

    Change Toast line code to

    Toast.makeText(getBaseContext(),requestCode+"", Toast.LENGTH_SHORT).show();
    

    or

    Toast.makeText(getBaseContext(),String.valueOf(requestCode), Toast.LENGTH_SHORT).show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code so far: public class PostfixCalculator { private Stack<Float> stack; private
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is an example: I write html code inside of textarea, then I swap
here is my php code $titikPetaInti = array(); while($row = mysql_fetch_assoc($hasil2)) { $titikPetaInti[] =
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here is a code snippet I was working with: int *a; int p =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.