我正在尝试开发一种自动检测歌曲情绪的程序。我将我的项目从一台笔记本电脑转移到另一台在那里完成,并且有一个错误不断出现。已经搜索了很多但没有找到解决方案。 这是问题仍然存在的代码。 package featureExtractor;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.ObjectInputStream;
import java.io.ObjectInputStream.GetField;
import java.io.ObjectStreamClass;
import java.nio.file.CopyOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.io.Serializable;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JWindow;
import ui.Test;
import weka.classifiers.Classifier;
import weka.core.Attribute;
import weka.core.Instances;
import weka.gui.Main;
import weka.gui.visualize.VisualizePanel;
public class Classify{
static String curDir = System.getProperty("user.dir");
private static String happy = curDir+"\\Playlists\\Happy";
private static String rel = curDir+"\\Playlists\\Relaxed";
private static String rom = curDir+"\\Playlists\\Romantic";
private static String sad = curDir+"\\Playlists\\Sad";
private static Test aa ;
public static String[] mood;
static CopyOption[] options = new CopyOption[]{
StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES
};
public Classify(Test test) {
// TODO Auto-generated constructor stub
Classify.aa=test;
}
public static void main(String[] args) throws Exception
{
Icon icon=null;
Path original = Paths.get(aa.getFile().getAbsolutePath());
File file = new File(aa.getFile().getAbsolutePath());
System.out.println("Classifying");
BufferedReader reader = new BufferedReader(new FileReader(args[0]));
Instances data = new Instances(reader);
reader.close();
data.setClassIndex(data.numAttributes()-1);
Classifier cls = (Classifier)weka.core.SerializationHelper.read(curDir+"/src/resources/MetaBag.model");
mood = new String[data.numInstances()];
if(data.numInstances()==1)
{
double b = cls.classifyInstance((data.instance(0)));
Attribute a1 = data.classAttribute();
String moodSin = a1.value((int) b);
switch(moodSin)
{
case "Happy":
icon = (Icon)(new ImageIcon(ClassLoader.getSystemResource("resources/happy.png")));
java.nio.file.Files.copy(original,Paths.get(happy+"/"+file.getName()), options);
break;
case "Romantic":
icon = (Icon)new ImageIcon(ClassLoader.getSystemResource("resources/rom.jpg"));
java.nio.file.Files.copy(original,Paths.get(rom+"/"+file.getName()), options);
break;
case "Sad":
icon = (Icon)new ImageIcon(ClassLoader.getSystemResource("resources/sad.png"));
java.nio.file.Files.copy(original,Paths.get(sad+"/"+file.getName()), options);
break;
case "Relaxed":
icon = (Icon)new ImageIcon(ClassLoader.getSystemResource("resources/relaxed.png"));
java.nio.file.Files.copy(original,Paths.get(rel+"/"+file.getName()), options);
}
JOptionPane.showMessageDialog((Main.getFrames())[0], "The Mood of the song is " +moodSin, "And the Mood is", JOptionPane.INFORMATION_MESSAGE, icon);
}
else
{
for(int i=0;i<data.numInstances();i++)
{
double b = cls.classifyInstance((data.instance(i)));
Attribute a1 = data.classAttribute();
mood[i] = a1.value((int) b);
updateDisplay(i,mood[i]);
}
makePlaylist();
}
}
public static void updateDisplay(int i,String mood)
{
String temp = aa.getFileNames()[i];
aa.getTextArea().append((i+1)+ ". "+ temp +" - "+ mood+System.getProperty("line.separator"));
}
public static void makePlaylist()
{ String[] temp = aa.getFileNames();
aa.getTextArea().append("Creating Playlist"+System.getProperty("line.separator"));
for(int i=0;i<aa.getFileNames().length;i++)
{
try
{
switch(mood[i])
{
case "Happy":
java.nio.file.Files.copy(Paths.get(temp[i]),Paths.get(happy+"/"+new File(temp[i]).getName()), options);
break;
case "Romantic":
java.nio.file.Files.copy(Paths.get(temp[i]),Paths.get(rom+"/"+new File(temp[i]).getName()), options);
break;
case "Sad":
java.nio.file.Files.copy(Paths.get(temp[i]),Paths.get(sad+"/"+new File(temp[i]).getName()), options);
break;
case "Relaxed":
java.nio.file.Files.copy(Paths.get(temp[i]),Paths.get(rel+"/"+new File(temp[i]).getName()), options);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
aa.getTextArea().append("Playlist Created"+System.getProperty("line.separator"));
JOptionPane.showMessageDialog((Main.getFrames())[0], "Playlist Created. Please check the Progress Box for the results", "All Done!", JOptionPane.INFORMATION_MESSAGE,null );
}
}
这是错误。
java.io.InvalidClassException: weka.classifiers.meta.Bagging; local class incompatible: stream classdesc serialVersionUID = -5178288489778728847, local class serialVersionUID = -115879962237199703
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weka.core.SerializationHelper.read(SerializationHelper.java:278)
at weka.core.SerializationHelper.read(SerializationHelper.java:263)
at featureExtractor.Classify.main(Classify.java:72)
at featureExtractor.Addmood.main(Addmood.java:62)
at featureExtractor.FeaturesExtractor.main(FeaturesExtractor.java:315)
at ui.Test$2$1.run(Test.java:184)
at java.lang.Thread.run(Unknown Source)
不知道这是一线错误,也无法理解为什么它说'&34;未知来源&#34;。