crashing android

Hay Guy, I'm using 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?



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

    @Override public void onCreate(Bundle savedInstanceState) {
        try {
            usenet.connect("", 563);
        } catch (SocketException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block

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* with android

I'm having a problem using the* 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 cannot be resolved

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

android - freezing interaction and animations

I'm using 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: Android Studio

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

java - Error when logging into FTP from AsyncTask class using

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 '', 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 FTPSClient connect very slow

I am using the 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:

I'm trying to upload an image to ftp server using this AsyncTask: import android.content.Context; import android.os.AsyncTask; import; import; import; import; 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) | Android