sinat_35988648
dpwqb
2019-04-10 19:11
采纳率: 33.3%
浏览 536

调用weka API输出数据集抛出异常:java.lang.IndexOutOfBoundsException

能帮我找一下出错的原因吗?
这是我的代码,用以加载数据库数据并输出数据集。

 public void weka() {
        // 使用InstanceQuery类
        try {
            System.out.println("\n\n使用DatabaseLoader类从数据库中批量检索数据");
            DatabaseLoader loader = null;
            loader = new DatabaseLoader();
            loader.setSource("jdbc:mysql://127.0.0.1:3306/gtd_data", "root", "abcd=!@#");
            loader.setQuery("select * from tevent_all_info_copy");
            Instances data1 = loader.getDataSet();
            System.out.println("数据集内容:");
            System.out.println(data1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

下面是异常:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at java.util.ArrayList.rangeCheck(ArrayList.java:657)
    at java.util.ArrayList.get(ArrayList.java:433)
    at weka.core.Attribute.value(Attribute.java:778)
    at weka.core.AbstractInstance.stringValue(AbstractInstance.java:668)
    at weka.core.AbstractInstance.stringValue(AbstractInstance.java:644)
    at weka.core.AbstractInstance.toString(AbstractInstance.java:756)
    at weka.core.DenseInstance.toStringNoWeight(DenseInstance.java:330)
    at weka.core.AbstractInstance.toStringMaxDecimalDigits(AbstractInstance.java:692)
    at weka.core.AbstractInstance.toString(AbstractInstance.java:712)
    at java.lang.String.valueOf(String.java:2994)
    at java.lang.StringBuffer.append(StringBuffer.java:263)
    at weka.core.Instances.stringWithoutHeader(Instances.java:1867)
    at weka.core.Instances.toString(Instances.java:1851)
    at java.lang.String.valueOf(String.java:2994)
    at java.io.PrintStream.println(PrintStream.java:821)
    at test.NewTest.weka(NewTest.java:23)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐