question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Factory example does not work

See original GitHub issue

When trying to run FactoryExample.java the following error appears:

Exception in thread "main" java.lang.IllegalArgumentException: A MovingRoadUser can not be added on an already occupied position (1140.0,90.0).
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:146)
	at com.github.rinde.rinsim.core.model.road.CollisionGraphRoadModelImpl.addObjectAt(CollisionGraphRoadModelImpl.java:152)
	at com.github.rinde.rinsim.core.model.pdp.PDPObjectImpl.initRoadUser(PDPObjectImpl.java:77)
	at com.github.rinde.rinsim.core.model.road.AbstractRoadModel.doRegister(AbstractRoadModel.java:298)
	at com.github.rinde.rinsim.core.model.road.GenericRoadModel.register(GenericRoadModel.java:106)
	at com.github.rinde.rinsim.core.model.road.GenericRoadModel.register(GenericRoadModel.java:34)
	at com.github.rinde.rinsim.core.model.ModelManager.doRegister(ModelManager.java:95)
	at com.github.rinde.rinsim.core.model.ModelManager.register(ModelManager.java:115)
	at com.github.rinde.rinsim.core.Simulator.register(Simulator.java:110)
	at com.github.rinde.rinsim.examples.demo.factory.FactoryExample.run(FactoryExample.java:167)
	at com.github.rinde.rinsim.examples.demo.factory.FactoryExample.main(FactoryExample.java:97)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

The problem is at this line.

If we change it by

    for (int i = 0; i < NUM_VEHICLES; i++) {
      final List<Point> l = points.get(rng.nextInt(points.size()));
      final Point p = l.get(i);
      simulator.register(new AGV(p));
    }

it seems to work, but I don’t know if the purpose of this demo is to initialise the AGVs in certain positions. (Don’t think so, as they are initialised randomly).

Let me know if I have to create a PR to fix this issue.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexrscommented, May 1, 2017

I have tried in both 4.5.0-SNAPSHOT and 4.4.1 in Mac OS 10.11 with Java 1.8. I’ll try to reproduce the issue in another computer and I’ll keep you updated.

0reactions
rindecommented, May 8, 2017

Thanks for letting me know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solve application issues with the factory pattern
The factory pattern streamlines application issues, like when a developer must reply to users based upon the machine they are using.
Read more >
Factory Method Pattern Example in Java troubles
I'm trying to create a really simple Factory Method design pattern example in Java. I don't really know Java, I am new to...
Read more >
Factory Method Pattern - the problem and what does it do ...
First, object creation, broadly in the abstract, is not a responsibility; responsibilities should be more domain oriented. Second, your ...
Read more >
Understanding Design Patters: Factory Method
The factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to ......
Read more >
How to (Not) Create a Factory Function in JavaScript
In this article, we will look at how to create a factory function (aka the Crockford constructor) in JavaScript. Factory functions are an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found