OSGIフレームワークを使用して2つのバンドルを作成しています。1つは、与えられた行列の行列式を見つけるためのものであり、もう1つは、ユーザーから行列を取得するためのものです。knopflerfishフレームワークを使用してこれらのバンドルを実行しています。マトリックスに一定の値を取り、これらのバンドルを実行しているとき、それらは正しく機能しています。しかし、ユーザー入力を取得してknopflerfishのjarファイルで実行するためのコードを記述していると、nextInt()メソッドでエラーが発生します。この問題の解決策を教えてください。
これは、バンドルの作成に使用しているActivatorクラスのコードです。このバンドルの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;
}
}
例外は
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)