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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:10:49+00:00 2026-06-08T17:10:49+00:00

I’m using the Twilio API to send an SMS from my Twilio number to

  • 0

I’m using the Twilio API to send an SMS from my Twilio number to my cell.

I have two files:
1. a JSP file with a form and a method call
2. a java class with the Twilio API that receives the method call from item 1 and does the sending sms part
(see the files below)

Why am I getting the exception A “From” phone number is required?

The program works, delivers correctly, tried many times. I’m not getting an error. It works. It’s just that exception that puzzles me. I have purchased a twilio number, so I’m not using the trial number.

There is a stack trace associated with it, but can post it later.

In smsParams.put(“From”, from) I tried replacing from directly with a cell number like this (used a valid No):
smsParams.put(“From”, “1231231234”);
and then I get an exception that goes to the next line (smsParams.put(“To”, from);) and says A “To” number is required. When I replace variable with a number it skips to the next line and gives an exception for the message body.

Thanks

//***********************************
//java class MyMessage
//***********************************

package package_sms;
import java.util.HashMap;
import java.util.Map;
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.SmsFactory;
import com.twilio.sdk.resource.instance.Account;


public class MyMessage {

/** The Constant ACCOUNT_SID. */
public static final String ACCOUNT_SID = "AC11d68faa7db85a48557aa33ae0b88261";

/** The Constant AUTH_TOKEN. */
public static final String AUTH_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";


public String to, from, text;

    public void provideNumbers(String to, String from, String text)
    {
        // Create a rest client
        TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

        // Get the main account (The one we used to authenticate the client
        Account mainAccount = client.getAccount();

        // Send an sms
        SmsFactory smsFactory = mainAccount.getSmsFactory();
            Map<String, String> smsParams = new HashMap<String, String>();
        smsParams.put("From", from);    // Twillio No
        smsParams.put("To", to);        // target phone No
        smsParams.put("Body", text);    // message text
        try 
        {
            smsFactory.create(smsParams);
        } 
        catch (TwilioRestException e) 
        {
            e.printStackTrace();
        }   
    }



<% *****************************
// jsp file SendSms
***************************** %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="package_sms.MyMessage"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>form</title>
</head>
    <body style="background-color:Azure;">
        <h3>Welcome to your text messenger</h3>
        <form action="SendSms.jsp" name="form1" method="POST" >
        From: <input type="text" name="phoneFrom" style="background-color: Beige;border:1px solid Black;"/><br><br> 
        To: <input type="text" name="phoneTo" style="background-color: Beige;border:1px solid Black;"/><br><br>
        Message text: <input type="text" name="messageText" style="background-color: Beige;border:1px solid Black;"/><br><br>
        <input type="submit" name="submit" value="Send Message" />
        </form><br>

        <%  /* Declared string variables that provide parameters to the 
               call to provideNumber method. provideNumbers method is located in MyMessage class.
               provideNumbers method is called on a 'message' object.  */

        String number_from = request.getParameter("phoneFrom");
        String number_to = request.getParameter("phoneTo");
        String messageBody = request.getParameter("messageText");

        MyMessage message = new MyMessage();
            message.provideNumbers(number_to, number_from, messageBody);
            %>

    </body>
</html>
  • 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-08T17:10:50+00:00Added an answer on June 8, 2026 at 5:10 pm

    The error is in your JSP page. When the JSP is loaded it runs through executing all the code. Part of that code is you grabbing the inputs and calling your method.

    However when the file first loads there are no values in the form. Therefore the getParameter calls are getting null values. Therefore the “message.provideNumbers” method is passing your Java code nulls. This is turn means that when your Java code tries to call Twilio it is passing null values and an Exception is triggered.

    To correct this you could surround your JSP Java code in an IF statement checking that the variables have entries. For example:

    <% if (request.getParameter("phoneFrom") != null 
           && request.getParameter("phoneTo") != null 
           && request.getParameter("messageText") != null) {  
    
        String number_from = request.getParameter("phoneFrom");
        String number_to = request.getParameter("phoneTo");
        String messageBody = request.getParameter("messageText");
    
        MyMessage message = new MyMessage();
        message.provideNumbers(number_to, number_from, messageBody);
    }%>
    

    Hope that helps.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the

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.