I am creating two bundles using OSGI framework. One is for finding determinant of given matrix and another one is for taking matrix from user . I am running these bundles using knopflerfish framework. When I am taking constant value for matrix and running these bundles they are working properly. But when I am writing code for taking user input and running it in jar file in knopflerfish it is giving error in nextInt() method. Please give me solution of this problem.
This is the code for Activator class Which I am using for creating bundle.I am creting a jar file of this bundle and running it in knopflerfish. It is showing error in nextInt() method. I am not able to get user input. If I am running this program independently as java application it is working but in knopflerfish framework it is not working
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;
}
}
Exception is
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)
As an alternative to using
System.in
in your activator, I would recommend you use the Felix GoGo Shell (this is a bundle you can deploy into Knopflerfish as well). It provides a simple extender-model to add new commands, including command-completion.