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

  • SEARCH
  • Home
  • 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 8051499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:19:01+00:00 2026-06-05T07:19:01+00:00

I need to pass a long (_id) with an intent from Activity A to

  • 0

I need to pass a long (_id) with an intent from Activity A to Activity B, using this code:

Intent vip0= new Intent(this, PageSinglePlayerGuess.class);
vip0.putExtra("resid", (long) 1);
startActivity(vip0);

and getting it in Activity B with this method (called in onCreate()):

public long getResId() {
    Intent i= getIntent();
    resid= i.getLongExtra("resid", 1);
    Log.d("D", "Risorsa: " + resid);
    return resid;
}

resid in ActB is a long.
I get this error:

    06-06 11:10:47.138: W/Bundle(538): Key resid expected Long but value was a java.lang.Integer.  The default value 1 was returned.
    06-06 11:10:47.158: W/Bundle(538): Attempt to cast generated internal exception:
    06-06 11:10:47.158: W/Bundle(538): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
    06-06 11:10:47.158: W/Bundle(538):  at android.os.Bundle.getLong(Bundle.java:966)
    06-06 11:10:47.158: W/Bundle(538):  at android.content.Intent.getLongExtra(Intent.java:3874)
    06-06 11:10:47.158: W/Bundle(538):  at com.gmail.corsalini.celebrityquiz.PageSinglePlayerGuess.getResId(PageSinglePlayerGuess.java:60)
    06-06 11:10:47.158: W/Bundle(538):  at com.gmail.corsalini.celebrityquiz.PageSinglePlayerGuess.onCreate(PageSinglePlayerGuess.java:46)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.Activity.performCreate(Activity.java:4465)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    06-06 11:10:47.158: W/Bundle(538):  at android.os.Handler.dispatchMessage(Handler.java:99)
    06-06 11:10:47.158: W/Bundle(538):  at android.os.Looper.loop(Looper.java:137)
    06-06 11:10:47.158: W/Bundle(538):  at android.app.ActivityThread.main(ActivityThread.java:4424)
    06-06 11:10:47.158: W/Bundle(538):  at java.lang.reflect.Method.invokeNative(Native Method)
    06-06 11:10:47.158: W/Bundle(538):  at java.lang.reflect.Method.invoke(Method.java:511)
    06-06 11:10:47.158: W/Bundle(538):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    06-06 11:10:47.158: W/Bundle(538):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    06-06 11:10:47.158: W/Bundle(538):  at dalvik.system.NativeStart.main(Native Method)

Any idea how to solve this? (it seems really easy, but i just can’t get out of it)

  • 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-05T07:19:02+00:00Added an answer on June 5, 2026 at 7:19 am

    According to the log the problem seems to be in following:

    resid= i.getLongExtra("resid", 1);

    so change it to:

    resid= i.getLongExtra("resid", 1L);

    BTW: the getLongExtra implementation looks like this:

    public long getLongExtra(String name, long defaultValue) {
       return mExtras == null ? defaultValue : mExtras.getLong(name, defaultValue);
    }
    

    So that’s why see that it fails at line:

    at android.os.Bundle.getLong(Bundle.java:966)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to pass a long list of Ids from one page to another,
I need to pass data from HTML to Service using JSON (in JS/JQUERY )
I need to pass configuration settings to an AddIn created using the Managed AddIn
I am using JNI to pass data between C++ and Java. I need to
Sorry for this long post....But i have a headache from this task. I have
I need to pass a pointer through a scripting language which just has a
I need to pass audio data into a 3rd party system as a 16bit
I need to pass data to a variable in my master page each time
I need to pass an object (my own business object) between two tables in
I need to pass multiple arguments to a function that I would like to

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.