Java 我们如何从键盘向OSGI包提供输入。我想从用户那里获取矩阵元素

Java 我们如何从键盘向OSGI包提供输入。我想从用户那里获取矩阵元素,java,input,osgi,knopflerfish,Java,Input,Osgi,Knopflerfish,我正在使用OSGI框架创建两个包。一个是求给定矩阵的行列式,另一个是从用户那个里取矩阵。我使用knopflerfish框架运行这些包。当我为矩阵取常量值并运行这些包时,它们工作正常。但当我编写代码获取用户输入并在knopflerfish的jar文件中运行时,它在nextInt()方法中给出了错误。 请给我这个问题的解决办法 这是我用来创建bundle的Activator类的代码。我正在创建这个bundle的jar文件,并在knopflerfish中运行它。它在nextInt()方法中显示错误。我

我正在使用OSGI框架创建两个包。一个是求给定矩阵的行列式,另一个是从用户那个里取矩阵。我使用knopflerfish框架运行这些包。当我为矩阵取常量值并运行这些包时,它们工作正常。但当我编写代码获取用户输入并在knopflerfish的jar文件中运行时,它在nextInt()方法中给出了错误。 请给我这个问题的解决办法

这是我用来创建bundle的Activator类的代码。我正在创建这个bundle的jar文件,并在knopflerfish中运行它。它在nextInt()方法中显示错误。我无法获取用户输入。如果我作为java应用程序独立运行这个程序,它可以工作,但在knopflerfish框架中它不能工作

    package matrixuse;
    import java.util.Scanner;
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.osgi.framework.Constants;
    import org.osgi.framework.ServiceReference;
    import matrixCal.*;
    public class Activator implements BundleActivator {
    public static BundleContext bc = null;
    public void start(BundleContext bc) throws Exception {
    System.out.println(bc.getBundle().getHeaders().get(
    Constants.BUNDLE_NAME)+ " starting...");
    Activator.bc = bc;
    ServiceReference reference = bc.getServiceReference
    (MatrixCal.class.getName());
    MatrixCal service = (MatrixCal)bc.getService(reference);
    int rows, cols;
    MatrixInput m1=new MatrixInput();
    Scanner input = new Scanner(System.in);
    System.out.print("Enter number of rows: ");
    rows = input.nextInt();
    System.out.print("Enter number of columns: ");
    cols = input.nextInt();
    int array[][] = new int[rows][cols];
    System.out.println("Enter elements for Matrix");
    for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
     array[i][j] = input.nextInt();
        }
      }

    int result = service.determinant(array,array.length);
    System.out.println("Calculated Determinant is :"+ result);
    bc.ungetService(reference);
    }
    public void stop(BundleContext bc) throws Exception {
     Activator.bc = null;
    }
    }

作为在activator中使用
System.in
的替代方法,我建议您使用(这是一个捆绑包,您也可以部署到Knopflerfish中)。它提供了一个简单的方法,包括命令完成。

是否尝试重新启动?这通常对我有用。
    java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Unknown Source)
    at java.util.Scanner.next(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at java.util.Scanner.nextInt(Unknown Source)
    at matrixuse.Activator.start(Activator.java:24)
    at org.knopflerfish.framework.BundleImpl.start0(BundleImpl.java:356)
    at org.knopflerfish.framework.BundleThread.run(BundleThread.java:107)