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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:56:15+00:00 2026-06-14T08:56:15+00:00

With the following code, the server is getting hit, but I also want to

  • 0

With the following code, the server is getting hit, but I also want to send variables in POST method.

But it just gives me a null pointer exception. It has something to do with the OutputStream. I have checked postData … it has some address, which means it is not null.

So why I am given null pointer exception?

ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
try {
    connDesc = connFact.getConnection("http://example.com/login.php", Connector.READ_WRITE, returnContent);
    httpConn.setRequestMethod(HttpConnection.POST);
    httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
    encPostData.append("count", "Hell Yeah!");
    byte[] postData = encPostData.toString().getBytes("UTF-8");

    httpConn.setRequestProperty("Content-length", String.valueOf(postData.length));
    Dialog.alert("Post Data: " + postData);

    OutputStream os = httpConn.openOutputStream();
    os.write(postData);
    os.flush();
    httpConn = (HttpConnection) connDesc.getConnection();

    final int iResponseCode = httpConn.getResponseCode();
    UiApplication.getUiApplication().invokeLater(new Runnable() {
        public void run() {
            //Dialog.alert("Response code: " +  Integer.toString(iResponseCode));
        }
    });
} catch (IOException e) {
    System.err.println("Caught IOException: " + e.getMessage());
}
  • 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-14T08:56:16+00:00Added an answer on June 14, 2026 at 8:56 am

    You are misusing the ConnectionFactory.getConnection(String url, int transportType, String ConnectionUID) method. For instance, check what you pass as transportType…

    Here is what API says about return value:

    Returns: a ConnectionDescriptor if a connection can be established;
    null otherwise

    So, it just fails and returns null. And that’s why you get a NPE.

    UPDATE:

    I would recommend to just use a simpler API ConnectionFactory.getConnection(String url):

    ConnectionDescriptor cd = connFact.getConnection("http://example.com/login.php");
    if (cd == null) {
        // throw an error signalling there is no connectivity right now
    }
    HttpConnection httpConn = (HttpConnection) cd.getConnection();
    // the rest of the code working with httpConn ..
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send iPhone image to server database. I wrote following code. I
I am getting a date from server side C# using the following code: DateTime
The following code works on my laptop but doesn't work on remote server: <?php
I'm getting an error with the following code when trying to send an email.
It's early in the morning and I'm just not getting this: The following code
I have the following code. When deployed to a server, i m getting exception
I am not getting any exception in the following code, however I also don't
I have written following code for the client of RMI. But getting java.rmi.ConnectException: Connection
I used the following code for getting push notification. but i am getting an
I have the following code that suppose used to Send Data to Server using

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.