Java,Android:Jetty调度程序方法抛出NPE,不知道它在哪里被调用 [英] Java, Android : Jetty scheduler method throwing NPE, don't know where it's getting called

查看:95
本文介绍了Java,Android:Jetty调度程序方法抛出NPE,不知道它在哪里被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,在其中尝试初始化LongPollingTransport,如下所述.但是我从Jetty调度程序中得到了一个错误.我自己不是在叫Jetty Scheduler类.我怎样才能解决这个问题.任何帮助都很好.

I am working on an Android application in which I am trying to initialize a LongPollingTransport as mentioned below. But I am getting an error from Jetty scheduler. I am not calling the Jetty Scheduler class myself. How can I fix this. Any help would be nice.

代码:

public class ConsoleChatClient {


    private volatile String nickname = "kernel";
    private volatile BayeuxClient client;
    private final ChatListener chatListener = new ChatListener();
    private final MembersListener membersListener = new MembersListener();
    HttpClient httpClient = new HttpClient();

    public void run() throws IOException
    {


        String defaultURL = "http://localhost:8080/cometd/cometd";

        client = new BayeuxClient(defaultURL, new LongPollingTransport(null,httpClient));
        client.getChannel(Channel.META_HANDSHAKE).addListener(new InitializerListener());
        client.getChannel(Channel.META_CONNECT).addListener(new ConnectionListener());
//Line below throws an error
-->        client.handshake(); 
}

错误日志:

11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{internetlegion.twentynotes/internetlegion.twentynotes.Login.LoginActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'org.eclipse.jetty.util.thread.Scheduler$Task org.eclipse.jetty.util.thread.Scheduler.schedule(java.lang.Runnable, long, java.util.concurrent.TimeUnit)' on a null object reference
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:144)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:155)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5696)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:  Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'org.eclipse.jetty.util.thread.Scheduler$Task org.eclipse.jetty.util.thread.Scheduler.schedule(java.lang.Runnable, long, java.util.concurrent.TimeUnit)' on a null object reference
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.eclipse.jetty.client.TimeoutCompleteListener.schedule(TimeoutCompleteListener.java:53)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:675)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.transport.LongPollingTransport.send(LongPollingTransport.java:187)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient$BayeuxClientState.transportSend(BayeuxClient.java:1430)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient$BayeuxClientState.send(BayeuxClient.java:1425)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient.sendHandshake(BayeuxClient.java:403)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient$HandshakingState.execute(BayeuxClient.java:1526)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient.changeState(BayeuxClient.java:1082)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient.handshake(BayeuxClient.java:339)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at org.cometd.client.BayeuxClient.handshake(BayeuxClient.java:315)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at internetlegion.twentynotes.Activity.ConsoleChatClient.run(ConsoleChatClient.java:38)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at internetlegion.twentynotes.Login.LoginActivity.onCreate(LoginActivity.java:66)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5958)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:144) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:155) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5696) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028) 
11-12 10:56:38.317 19972-19972/internetlegion.twentynotes E/AndroidR

Build.gradle(对于应用程序)

Build.gradle (For app)

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.fasterxml.jackson.core:jackson-core:2.6.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.0'
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
    compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
        exclude group: 'org.springframework', module: 'commons-logging'
        exclude group: 'org.springframework', module: 'spring-core'
        exclude group: 'org.springframework', module: 'spring-web'
    }
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.6.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.tonicartos:superslim:0.4.13'
    compile 'commons-codec:commons-codec:1.9'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'org.cometd.java:bayeux-api:3.0.6'
    compile 'org.cometd.java:cometd-java-server:3.0.6'
    compile 'org.cometd.java:cometd-java-client:3.0.6'
    compile 'org.cometd.java:cometd-java-annotations:3.0.6'
}

任何帮助都会很好.非常感谢. :-)

Any help would be nice. Thanks a lot. :-)

编辑

最后我调试了它,发现HandshakeState.toString正在抛出NPE,但是由于这是一种库方法,所以我不知道该怎么办.

Finally I debugged it and found that HandshakeState.toString is throwing an NPE, but as this is a library method, I have no idea what to do about it.

错误:

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.cometd.client.BayeuxClient$HandshakingState.toString()

失败方法:

   private class HandshakingState extends BayeuxClientState
    {

--->        private HandshakingState(Map<String, Object> handshakeFields, ClientSessionChannel.MessageListener callback, ClientTransport transport)
        {
            super(State.HANDSHAKING, handshakeFields, callback, null, transport, null, 0);
        }

推荐答案

我怀疑HandshakingState.toString()会抛出NullPointerException,因为toString()唯一要做的就是将调用转发给枚举type字段.

I doubt HandshakingState.toString() throws an NullPointerException, since the only thing toString() does is to forward the call to the enum type field.

您的代码对我来说似乎是HttpClient没有启动.

What seems to me from your code is that the HttpClient is not started.

HttpClient实例被创建为类ConsoleChatClient中的一个字段,但是您从未对其调用start().

The HttpClient instance is created as a field in class ConsoleChatClient, but you never call start() on it.

这很重要,因为您可以有多个引用同一HttpClient实例的BayeuxClient实例,因此在使用BayeuxClient之前必须先启动HttpClient的生命周期.

This is important because you can have multiple BayeuxClient instances referring to the same HttpClient instance, so the lifecycle of HttpClient must be started before you are using BayeuxClient.

这篇关于Java,Android:Jetty调度程序方法抛出NPE,不知道它在哪里被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆