org.apache.commons.net.nntp crashing android

Hay Guy, I'm using org.apache.commons.net.nntp to connect to a nntp server, however running a simple nntp.connect(host, port) crashes the android.

Anyone got any ideas? Do java packages work with android straight out of the box? or do they need editing?

Thanks

import org.apache.commons.net.nntp.*;

public class newsdroid extends Activity {
    NNTP usenet; /** Called when the activity is first created. */

    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            usenet.connect("ssl-eu.astraweb.com", 563);
        } catch (SocketException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}


Asked by: Thomas488 | Posted: 20-01-2022






Answer 1

You need to initialize your variable usenet, by just using NTTP usenet its called declaring the variable. It just declares the variable to type NTTP and it has a reference to nothing, which is commonly defined as being null, hence the NullPointerException.

You might need to check out NTTPClient instead, so add this into your code

NTTPClient usenet = new NTTPClient();

That is initializing the variable usenet to a NTTPClient.

Answered by: Carlos958 | Posted: 21-02-2022



Answer 2

you haven't initialized the 'usenet' field, so you get a NullPointerException.

"NNTP usenet;" is equivalent to "NNTP usenet = null;".

Answered by: Elise723 | Posted: 21-02-2022



Similar questions

java - Problem using org.apache.commons.net.telnet.* with android

I'm having a problem using the org.apache.commons.net.telnet.* library in my Android application and I was hoping someone could help me. I have implemented an app which uses telnet to communicate with a remote server and all works fine. The problem I have is when I call TelnetClient.disconnect() the method does not return. When calling the method when running a test case (meaning sans And...


java - The import org.apache.commons.net cannot be resolved

Why am I getting this error? I already imported the jar file in my eclipse project.


android - org.apache.commons.net.ftp.FTPClient.storeFile freezing interaction and animations

I'm using org.apache.commons.net.ftp.FTPClient to communicate with an ftp server via an android app I'm making that records video and then uploads it to the ftp server. Everything is fine until I call storeFile at which point the app prevents any interaction until the uploading is completed. Is there any way around this? I'm currently developing for API lvl 12. My set up is as follows I have a class that calls a service in...


FATAL EXCEPTION: main java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient Android Studio

I know that this question has some replies as in: one two


java - Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient

I am logging into the ftp account using AsyncTask but I keep getting this error, 12-31 15:26:19.637: E/dalvikvm(5986): Could not find class 'org.apache.commons.net.ftp.FTPClient', referenced from method com.example.testme.Processing.connnectingwithFTP I can understand that my method inside Asynctask is not able to find the FTPClient class eventhough it is imported fine. But I don't how to ...


android - Apache org.apache.commons.net FTPSClient connect very slow

I am using the org.apache.commons.net.FTPSClient in Android and I am trying to connect to a FTP Server via FTPS. The connect method of the FTPSClient is very slow and this seems to depend on the Android Version. On a Nexus 6 with Android 6.0.1 the connect call needs 5 sec in average. On a Galaxy Nexus with Android 4.3 it only needs 1-2 sec in average. SSLContext sslContext; try ...


android - java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient

I'm trying to upload an image to ftp server using this AsyncTask: import android.content.Context; import android.os.AsyncTask; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; import java.io.FileInputStream; public class my_ftp_uploader extends AsyncTask<String, Void, String> { public String file_name; private Context con...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top