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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:03:59+00:00 2026-05-24T16:03:59+00:00

I am trying to write a program that will send GPS coordinates using telnet.

  • 0

I am trying to write a program that will send GPS coordinates using telnet.
I keep getting the following exception:

Exception in thread "Timer-0" java.lang.NullPointerException
at org.apache.commons.net.telnet.Telnet._sendByte(Telnet.java:1060)
at org.apache.commons.net.telnet.TelnetOutputStream.write(TelnetOutputStream.java:87)
at org.apache.commons.net.io.ToNetASCIIOutputStream.write(ToNetASCIIOutputStream.java:77)
at org.apache.commons.net.io.ToNetASCIIOutputStream.write(ToNetASCIIOutputStream.java:111)
at java.io.PrintStream.write(PrintStream.java:430)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:85)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:168)
at java.io.PrintStream.write(PrintStream.java:477)
at java.io.PrintStream.print(PrintStream.java:619)
at java.io.PrintStream.println(PrintStream.java:756)
at com.example.myandroid.gpsSender$1.run(gpsSender.java:34)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)

I don’t know why I am getting this. Can you please tell me? thanks
Here is my code:

package com.example.myandroid;

import org.apache.commons.net.telnet.TelnetClient;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.SocketException;
import java.util.Timer;
import java.util.TimerTask;

public class gpsSender {
    private TelnetClient telnet = new TelnetClient();

    public static void main(String[] args) throws Exception {
        gpsSender client = new gpsSender();
        client.start();
    }

    public String start() throws Exception {

        // Connect to the specified server

        telnet.connect("localhost", 5554);

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            float longitude = 1;
            float latitude = 1;
            int count = 0;
            PrintStream out = new PrintStream(telnet.getOutputStream());

            public void run() {
                out.println("geo fix " + String.valueOf(longitude) + " "
                        + String.valueOf(latitude));
                out.flush();
                System.out.println("geo fix " + String.valueOf(longitude) + " "
                        + String.valueOf(latitude));
                longitude++;
                latitude++;
                count++;
                if (count > 1000) {
                    cancel();
                }
            }
        }, 0, 1000);
        try {
            telnet.disconnect();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return ("Done");
    }

    public void write(String value) {
        try {

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
  • 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-24T16:04:00+00:00Added an answer on May 24, 2026 at 4:04 pm

    The line

     telnet.disconnect();
    

    is going to execute, so you won’t have an output stream to write to, hence the NPE. You should remove that line.

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

Sidebar

Related Questions

I am using Linux. I am trying to write a program in c that
I'm trying to write a program in Scala, that will accept SOAP-requests, get the
I'm trying to write a program that will loop through cells of a specific
I'm trying to write a program that will play MP3's. This program will also
I am trying to write a simple Ruby program that I will run from
I'm trying to write a program in R that when, given a vector, will
I am trying to write a simple program that lets me overlay a dot
I am writing a C program that will read and write from/to a serial
I am trying to write a Java application that will query the WMI on
I'm really new to this. I am trying to write a CGI program that

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.