【问题标题】:Why am i getting "UnsupportedOperationException" when receiving files?为什么接收文件时出现“UnsupportedOperationException”?
【发布时间】:2017-12-12 08:36:52
【问题描述】:

我有一个小组作业,每当我收到文件时,它都会显示 throw new UnsupportedOperationException("尚不支持。");

这到底是什么意思?我该如何修复/预防它?

这是我收到的文件之一,例如:

public class Interleave {
// TODO: write your code below this comment
// You must write a method that will interleave two arrays,
// producing a result array.  The resulting array should begin
// with the first element of the first given array.
// For example, the correct output for the setup in main is:
//
// 0, 1, 2, 3, 4, 5, 6,
//
// The test suite in InterleaveTest.java provides more examples.
// If one array is larger than the other, the extra elements should
// be put onto the end of the result array.  For example,
// if interleaving:
//
// first:  new int[]{0, 1}
// second: new int[]{5, 6, 7, 8}
//
// ...the result should be:
//
// new int[]{0, 5, 1, 6, 7, 8}
//
// If interleaving:
//
// first:  new int[]{5, 6, 7, 8}
// second: new int[]{0, 1}
//
// ...the result should be:
//
// new int[]{5, 0, 6, 1, 7, 8}
//

// DO NOT MODIFY main
public static void main(String[] args) {
    int[] first = new int[]{0, 2, 4, 6};
    int[] second = new int[]{1, 3, 5};
    int[] retval = interleave(first, second);
    for (int x = 0; x < retval.length; x++) {
        System.out.print("" + retval[x] + ", ");
    }
    System.out.println();
}

static int[] interleave(int[] first, int[] second) {
    throw new UnsupportedOperationException("Not supported yet."); 
    }
}

【问题讨论】:

  • 表示你的任务是实现那个操作。
  • 最好的解决办法是实现这个方法,你不觉得吗?
  • 有两种方法:maininterleave。有一条评论说“不要修改 main”。现在是真正重要的问题:您认为您需要修改哪种方法??? 提示: 这不是main

标签: java


【解决方案1】:

UnsupportedOperationException 更像 NotYetImplementedTODOInsertYourCodeHere。只需删除带有throw new UnsupportedOperationException("Not supported yet."); 的行并将您的代码放在那里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多