我创建客户端和服务器,然后在添加客户端类的序列化的目的,然后简单地刚走到客户在我的硬盘驱动器的文件夹,并将其粘贴到服务器correponding位置,都classname.class和classname.java分别.
它在我自己的笔记本电脑上运行良好但是当我想继续我在其他系统上工作时,当我打开项目文件夹并在客户端尝试连接到服务器后,出现以下错误:
Exception in thread "main" java.io.InvalidClassException: projectname.clasname; local class incompatible: stream classdesc serialVersionUID = -6009442170907349114, local class serialVersionUID = 6529685098267757690
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1582)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?是因为我使用较旧版本的IDE运行程序?
import java.io.Serializable;
import java.net.URL;
public class KeyAdr implements Serializable {
private static final long serialVersionUID = 6529685098267757690L;
public URL adr;
public String key;
}
Run Code Online (Sandbox Code Playgroud) 考虑以下功能
private static void GetText(String nodeValue) throws IOException {
if(!file3.exists()) {
file3.createNewFile();
}
FileOutputStream fop=new FileOutputStream(file3,true);
if(nodeValue!=null)
fop.write(nodeValue.getBytes());
fop.flush();
fop.close();
}
Run Code Online (Sandbox Code Playgroud)
添加什么以使其在下一行中每次写入?
例如,我想要一个单独的lline中给定字符串的每个单词,例如:
i am mostafa
Run Code Online (Sandbox Code Playgroud)
写道:
i
am
mostafa
Run Code Online (Sandbox Code Playgroud) 我正在使用Lobo - Java Web浏览器库,它给了我一个例外,经过一些研究后我确定可能是因为该库已经与旧版本的Java进行了编译.
代码如下:
import java.io.IOException;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.parser.DocumentBuilderImpl;
import org.lobobrowser.html.parser.InputSourceImpl;
import org.lobobrowser.html.test.SimpleUserAgentContext;
import org.xml.sax.SAXException;
public class Cobratest
{
public static void main(String[] args) throws SAXException, IOException
{
UserAgentContext uAgent = new SimpleUserAgentContext();
DocumentBuilderImpl docBuild = new DocumentBuilderImpl(uAgent);
docBuild.parse(new InputSourceImpl("http://dic.amdz.com/"));
}
}
Run Code Online (Sandbox Code Playgroud)
并且堆栈跟踪是:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface sun.font.FontManager, but class was expected
at org.lobobrowser.util.gui.FontFactory.createFont(FontFactory.java:210)
at org.lobobrowser.util.gui.FontFactory.createFont_Impl(FontFactory.java:180)
at org.lobobrowser.util.gui.FontFactory.createFont(FontFactory.java:127)
at org.lobobrowser.util.gui.FontFactory.getFont(FontFactory.java:98)
at org.lobobrowser.html.style.StyleSheetRenderState.<clinit>(StyleSheetRenderState.java:43)
at org.lobobrowser.html.domimpl.NodeImpl.<clinit>(NodeImpl.java:39)
at org.lobobrowser.html.parser.DocumentBuilderImpl.createDocument(DocumentBuilderImpl.java:143)
at org.lobobrowser.html.parser.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:97)
Run Code Online (Sandbox Code Playgroud)
当我检查时,org.lobobrowser.util.gui.FontFactory.createFont我发现有一个FontManager名称从之前版本的Java改变了.在这个 …
考虑下面的代码以及HashSet4s在其他地方填充的事实.
我的目标是包含所有4个HashSets中常见的所有元素.
我的问题是,首先,我做得对吗?其次,如果我做得对,有没有更好的方法呢?如果没有,那么我对此问题有什么解决方案?
static Set<String> one=new HashSet<>();
static Set<String> two=new HashSet<>();
static Set<String> three=new HashSet<>();
static Set<String> four=new HashSet<>();
private static void createIntersectionQrels() {
ArrayList<String> temp = new ArrayList<>();
Set<String> interQrels = new HashSet<>();
temp.addAll(one);
one.retainAll(two);
interQrels.addAll(one);
one.addAll(temp);
one.retainAll(three);
interQrels.addAll(one);
one.addAll(temp);
one.retainAll(four);
interQrels.addAll(one);
one.addAll(temp);
interQrels.retainAll(two);
interQrels.retainAll(three);
interQrels.retainAll(four);
}
Run Code Online (Sandbox Code Playgroud) 如何在双精度数组中找到最小的正(非零)数?例如,如果数组包含0.04,0.0001以及0.0,我要回0.0001.
下面的功能很好,但它会以min为单位返回零,这不是我感兴趣的.
static double[] absOfSub = new double[100];
...
private static double compare(double[] ds) {
double min = absOfSub[0];
for (double d : ds) {
min = Math.min(min, d);
}
return min;
}
Run Code Online (Sandbox Code Playgroud)
如何让它忽略零?
我写了这个程序来从树中删除一个节点,但它仍然存在!
怎么会发生这种情况?打印节点内容后,它仍然显示与删除节点内容之前相同的内容,这意味着它仍然存在!
码:
public class JavaApplication38 {
public static void check(Node node){
if (node == null || node.getNodeName() == null)
return;
check(node.getFirstChild());
System.out.println(node.getNodeValue() != null && node.getNodeValue().trim().length() == 0 ? "" : node);
if ( "abcd".equals(node.getTextContent()))
node.getParentNode().removeChild(node);
check(node.getNextSibling());
}
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
File file = new File("d:\\a.xml");
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(file);
document.getDocumentElement().normalize();
Node b=document.getFirstChild();
check(b);
check(b);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个double[]它有一个值NaN.当我添加数组的元素时,也会NaN产生结果NaN.
这是怎么发生的?如何防止将NaN其添加到我的数组的其余部分?
我有以下代码,并希望在将它们乘以我的10之后打印列表元素,但它表示不允许使用void.怎么解决?
List<Integer> integerList = Arrays.asList(10,22,30);
long muliplied = integerList.stream()
.map(e -> e*10)
.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud) 我是新手,Python并决定在TestDome. 以下是该网站上一个简单问题的代码,但由于它没有按应有的方式打印结果,因此我的分数为零。
class IceCreamMachine:
all={}
def __init__(self, ingredients, toppings):
self.ingredients = ingredients
self.toppings = toppings
def scoops(self):
for i in range(0,len(self.ingredients)):
for j in range(0,len(self.toppings)):
print ([self.ingredients[i],self.toppings[j]])
machine = IceCreamMachine(["vanilla", "chocolate"], ["chocolate sauce"])
print(machine.scoops()) #should print[['vanilla', 'chocolate sauce'], ['chocolate', 'chocolate sauce']]
Run Code Online (Sandbox Code Playgroud)
任何人都可以给一个提示如何解决它?
使用中的slice方法Python我们可以轻松地反转字符串和数字。但是,当数字为负数时怎么办?
def reverse(x):
string = str(x)
return int(string[::-1])
print(reverse(-123))
Run Code Online (Sandbox Code Playgroud)
返回时出现错误 321-
编辑:
现在让我们再做两个假设:
如果反转数不在[?2^31, 2^31 ? 1]其中,则应返回 0。
对于像 那样的数字120,它应该21以相反的形式返回。
现在,我们怎样才能逆转-120成-21?
我写了以下代码
我的目标是获得最低值,doble[] absOfSub但它在线上给出了以下异常 compared= Double.compare(d2, d1);
Exception in thread "main" java.lang.StackOverflowError
Run Code Online (Sandbox Code Playgroud)
为什么溢出以及如何解决它?
public class TestThe {
static double[] absOfSub = new double[5];
private static int index=0;
private static int compare(int currentIdx, int minIdx) {
if(index < absOfSub.length) {
if(absOfSub[currentIdx] < absOfSub[minIdx]) {
compare(currentIdx + 1, currentIdx);
} else {
compare(currentIdx + 1, minIdx);
}
}
return minIdx;
}
public static void main(String[] args) {
absOfSub[0]=1000;
absOfSub[1]=810;
absOfSub[2]=108;
absOfSub[3]=130;
absOfSub[4]=110;
double result;
int inndex= compare(0,1);
System.out.println(absOfSub[inndex]);
}
}
Run Code Online (Sandbox Code Playgroud)