开发者

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 (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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜