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 6558019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:08:52+00:00 2026-05-25T13:08:52+00:00

Hi working on an Android SMS application in scala alls going fine expect I

  • 0

Hi working on an Android SMS application in scala alls going fine expect I just cant find the way to write the following java code in scala. Any help appreciated

//---retrieve the SMS message received---
    Object[] pdus = (Object[]) bundle.get("pdus");  
    msgs = new SmsMessage[pdus.length];             
        for (int i=0; i<msgs.length; i++){  
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);   

I must admit I dont know how to write Object[] in scala its not java.util.ArrayList[java.lang.Object]
I have tried using the Bundle.getStringArrayList to get a List[String] and the do a getBytes on the strings but that not working …
My last attempt was:

//I know I should be using an Option ...  
def getSmsListFromIntent(intent:Intent):List[SmsMessage]= {  
    val bundle = intent.getExtras()  
    var ret:List[SmsMessage]= null  
    if (bundle != null)   
        ret= for { pdu <- bundle.getStringArrayList("pdus").toList } yield  
SmsMessage.createFromPdu( pdu.getBytes())
    else ret= List()  
    ret  

java code comes from: http://mobiforge.com/developing/story/sms-messaging-android
Thanks for any help

  • 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-05-25T13:08:52+00:00Added an answer on May 25, 2026 at 1:08 pm

    The following answers the question in the title and may not be the best way to approach the problem. Take it for what it’s worth.


    The literal translation of a cast in Scala is asInstanceOf:

    var x: Object = Array("foo", "bar");
    var y = x.asInstanceOf[Array[Object]];    
    >> x: java.lang.Object = Array(foo, bar)
    >> y: Array[java.lang.Object] = Array(foo, bar)
    

    However, as a fun exercise, why does this result in a ClassCastException?

    var x: Object = Array(1, 2);
    var y = x.asInstanceOf[Array[Object]];    
    

    Happy coding

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an SMS Application for Android, which undoubtedly needs to send SMSes
I am working on an android application and I want to send an SMS
I'm working with Android and I really need a fast way to get a
I have just begun working with the Android SDK and I am having problems
While working my way through the Android tutorials, I came across something I don't
I'm working on a client-server Android application and trying to figure out how to
I am working in android application retrieve image in sdcard in image read in
Hi I am working Android application development using titanium studio.I have developed small application.my
Just started working with android and ran into a small problem. I am have
I have just started working with Android ListView . However, setAdapter function in my

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.