Posted By:
Nitin_Gupta
Posted On:
Friday, September 7, 2001 05:49 AM
I have written the class Employee and Department as follows: class Employee { int EmpID; double Salary; } class Department { int EmpNo; Employee Emp[] = new Employee [3]; } I have declared a native method named GetTotalSalary() in the class named Native as follows: public class Native { public native static void GetTotalSalary(Department dept); static { System.loadLibrary("SampleNative"); } } The G
More>>
I have written the class Employee and Department as follows:
class Employee
{
int EmpID;
double Salary;
}
class Department
{
int EmpNo;
Employee Emp[] = new Employee
[3];
}
I have declared a native method named GetTotalSalary() in the class named Native as follows:
public class Native
{
public native static void GetTotalSalary(Department dept);
static
{
System.loadLibrary("SampleNative");
}
}
The GetTotalSalary() Method will not return any thing, but it will show the Total salary of all the Employees of the Department in a MessageBox. This method has to be implemented in VC++ or C++.
My Application CallNative is as follows:
public class CallNative
{
Native nat = new Native();
Department Dept = new Department();
public static void main(String args[])
{
CallNative call = new CallNative();
call.FillData();
call.nat.GetTotalSalary(call.Dept);
}
public void FillData()
{
Dept.EmpNo = 3;
Dept.Emp[0] = new Employee();
Dept.Emp[1] = new Employee();
Dept.Emp[2] = new Employee();
Dept.Emp[0].EmpID = 101;
Dept.Emp[0].Salary = 5000.0;
Dept.Emp[1].EmpID = 302;
Dept.Emp[1].Salary = 16000.0;
Dept.Emp[2].EmpID = 303;
Dept.Emp[2].Salary = 17000.0;
}
}
I got the follwing signature of the native method while I run javah:
JNIEXPORT void JNICALL Java_Native_GetTotalSalary
(JNIEnv *, jclass , jobject );
I am unable to access the elements of Employee class. Please Help me and implement the above function in VC++ or C++.
Thanks,
Nitin Gupta
<<Less