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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:31:14+00:00 2026-05-24T22:31:14+00:00

With something that I thought was so simple, I’m surprised to be getting such

  • 0

With something that I thought was so simple, I’m surprised to be getting such a strange error…

In my program, I have a layout with 5 buttons on it. When you press a button, it launches the phone’s dialer with the number pre-loaded into it. I’ve had no problem with this before, but then I tried moving the phone numbers to strings in an XML file that I put in the /res/values folder called ‘phone.xml’. Here’s a portion of my code for the Java file:

    public void launchDialer(String number){
        String numberToDial = "tel:"+number;
        startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(numberToDial)));
    }

    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.police_button1:
            launchDialer(Integer.toString(R.string.police1_phone));
            break;
        case R.id.police_button2:
            launchDialer("" + R.string.police2_phone);
            break;
        case R.id.police_button3:
            launchDialer("" + R.string.police3_phone);
            break;
        case R.id.police_button4:
            launchDialer("" + R.string.police4_phone);
            break;
        case R.id.police_button5:
            launchDialer("" + R.string.police5_phone);
            break;
        }
    }

And here’s my phone.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="police1_phone">"555-555-5555"</string>
    <string name="police2_phone">1-800-555-5555</string>
    <string name="police3_phone">555-555-5555</string>
    <string name="police4_phone">555-555-5555</string>
    <string name="police5_phone">555-555-5555</string>
</resources>

As you can see in the Java file, I tried something different for police1_phone and police2_phone, but neither of them worked. You can also see I tried putting quotes around 1 of the phone numbers in the xml file, but it still didn’t work. My output has always been some random 7 digit number that wasn’t even close to the phone number I wanted it to print. This Java code worked:

launchDialer("555-555-5555");

But, I need it to read from an XML file. Any ideas?

  • 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-24T22:31:15+00:00Added an answer on May 24, 2026 at 10:31 pm

    Maybe I don’t understand something, but getString(R.string.police1_phone) must work.

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

Sidebar

Related Questions

I'm trying to do something that I thought ought to be reasonably simple but
I want to do something that I thought would be very simple. I want
I want to do something that I thought was fairly simple. Produce a comma
Im trying to do something that I originally thought would be quite simple, but
I am having trouble doing something that is probably pretty simple! I have a
Hallo, i would like to do something that i thought would be fairly simple:
I'm trying to do something that I thought would be quite simple but as
I have a program that generates a plain text file. The structure (layout) is
I'm trying to do something that I thought was simple but doesn't appear to
I'm having trouble with something that I thought would be easy... I can't get

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.