-----------------------------------------
Exception in thread "Thread-0" java.lang.NullPointerException
at flex.testdrive.feed.Feed$FeedThread.run(Feed.java:61)
-------------------------------------------------------------------
package flex.testdrive.feed;
import java.util.*;
import flex.messaging.MessageBroker;
import flex.messaging.messages.AsyncMessage;
import flex.messaging.util.UUIDUtils;
public class Feed {
private static FeedThread thread;
public Feed() {
}
public static void main(String args[]){
Feed fd = new Feed();
fd.start();
}
public void start() {
if (thread == null) {
thread = new FeedThread();
thread.start();
}
}
public void stop() {
thread.running = false;
thread = null;
}
public static class FeedThread extends Thread {
public boolean running = true;
public void run() {
MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
String clientID = UUIDUtils.createUUID();
Random random = new Random();
double initialValue = 35;
double currentValue = 35;
double maxChange = initialValue * 0.005;
while (running) {
double change = maxChange - random.nextDouble() * maxChange * 2;
double newValue = currentValue + change;
if (currentValue < initialValue + initialValue * 0.15
&& currentValue > initialValue - initialValue * 0.15) {
currentValue = newValue;
} else {
currentValue -= change;
}
AsyncMessage msg = new AsyncMessage();
msg.setDestination("feed");
msg.setClientId(clientID);
msg.setMessageId(UUIDUtils.createUUID());
msg.setTimestamp(System.currentTimeMillis());
msg.setBody(new Double(currentValue));
msgBroker.routeMessageToService(msg, null);
System.out.println("" + currentValue);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
}
}
}
4 个解决方案
#1
是 msgBroker.routeMessageToService(msg, null); 这段代码 出现错误
#2
各位都没遇到过 这些情况吗? 指点 指点一下
#3
#4
我也遇到了,是msgBroker为null,不知道肿么回事
#1
是 msgBroker.routeMessageToService(msg, null); 这段代码 出现错误
#2
各位都没遇到过 这些情况吗? 指点 指点一下
#3
#4
我也遇到了,是msgBroker为null,不知道肿么回事