嘿我AccessControlException: access denied在尝试启动我正在编写的RMI应用程序时遇到了问题,如果我在默认端口1099上打开它,或者在另一个动态端口,我的策略文件当前打开它,我无法理解为什么会出现此异常授予一切(在应用完成后会改变).
我被困在哪里出错了,任何帮助都会很有用
我的代码
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {
if (System.getSecurityManager() == null)
{
System.setSecurityManager ( new RMISecurityManager() );
}
CreditCardServer ccs = new CreditCardServer();
int port = 1099;
try {
port = Integer.valueOf(args[0]);
}
catch (Exception e)
{
System.out.println("Invlaid Port");
}
if (((port <= 65535) && (port >= 49152)) || port ==1099)
{
System.out.println("Valid Port");
}
else
{ …Run Code Online (Sandbox Code Playgroud) 嘿SO Guru,我对这段代码有一点工作
public void kill(double GrowthRate, int Death)
{
int before = population.size();
for (PopulationMember p : population)
{
int[] probs = ProbablityArrayDeath(GrowthRate,Death,(int)p.fitness());
if (probs[RandomNumberGen.nextRandomInt(0, 99)]==0)
{
population.remove(p);
}
}
System.out.println("Intial Population: "+before+", Deaths:"+(before- population.size())+", New Population: "+population.size());
}
Run Code Online (Sandbox Code Playgroud)
当我第一次尝试运行代码时运行我的程序时,它会遇到此错误
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
at java.util.HashMap$KeyIterator.next(HashMap.java:828)
at Genetics.Population.kill(Population.java:181)
at Genetics.Population.run(Population.java:47)
at Control.Main.main(Main.java:35)
Run Code Online (Sandbox Code Playgroud)
稍微晃了一下这似乎是一个错误,通常会发生在线程为什么他们尝试同时访问相同的资源,但这就是让我在这个系统中完全没有多线程的原因.
有人可以解释为什么会这样,或者想到一个黑客来解决它
非常感谢^ _ ^
我是一名Java程序员,有一点C知识谁想要开始使用C++,有人可以推荐一个好的教程吗?
也有任何帮助:
好的我有一个程序:
我的问题在第2和第3阶段之间,我需要等待文件完成打印,直到我可以删除它.
仅供参考:打印需要5-10分钟(在旧计算机上打印大文件)
所以我需要从Java能够检查是否:
defualt打印队列是空的
文件正在使用中(注意:File.canWrite()在打印时返回true)
这是我的代码,用于构建一个可能的城市之旅Locale l(这不是最佳的,只是为了让我的AI搜索起步).
我得到了一个ConcurrentModificationException,据我所知,当多个代码访问变量/集合并尝试修改它时.导致此代码变得不快乐:
final void checkForComodification() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
}
Run Code Online (Sandbox Code Playgroud)
我修改它,因为我正在添加一个元素,但由于Iterator没有添加(仅删除)的方法,我正在使用集合的方法.
所以,我的问题是:
modCount正确,我没有得到ConcurrentModificationException?下面的完整方法,对ConcurrentModificationException发生的行进行评论:
public void construct() {
tour = new ArrayList();
ArrayList<City> lcl = new ArrayList(l.getCitys());
tour.add(lcl.remove(0));
tour.add(lcl.remove(1));
while (!this.tourComplete()) {
System.out.println(tour.size());
Iterator tourit = tour.iterator();
City g1 = (City) tourit.next();
City g2 = (City) tour.get(lcl.indexOf(g1)+1);
int gapDist = l.distanceBetweenCitys(g1, g2);
while (tourit.hasNext()) {
City C = null;
int best = Integer.MAX_VALUE;
for …Run Code Online (Sandbox Code Playgroud) 我试图在Java中第一次使用泛型类型,因为我只希望我的构造函数接受实现"Anealable"接口的类.由于我得到的唯一错误,我的代码出现问题是"类型的非法启动",试图使其工作并没有走得太远
这是我班级的代码
package simulated_anealing;
public class Crystal extends Thread {
Object a;
public Crystal(<? implements Anealable> a)
{
this.a = a;
}
}
Run Code Online (Sandbox Code Playgroud)