开发者

org.apache.commons.net.nntp crashing android

开发者 https://www.devze.com 2022-12-18 18:56 出处:网络
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.

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 (SocketExceptio开发者_JS百科n e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}


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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号