The array T0[] or T1[] or T2[] doesn't have the items you are indexing so strangely, or the array g[] doesn't have 2913 items.
I can't see any reason why you should use JNI for this. It can be done perfectly well in Java, probably better actually.
Question
I need to call function C function "hashvalue(string)" inside my java program decryption(). I used JNI to build .dll library called HashValue.dll. The issue is whenever i call hashvalue, the java program terminates. Here is my headerfile, C program and the java program. java Program
BufferedReader line = null;
String support="";
int itemhashtableno;
int maxhashvalue;
int itemsetsize;
try {
line = new BufferedReader(new FileReader("F:/workspace/MTechProject-Frugal Scheme/src/authors205.txt"));
String itemset;
while((itemset=line.readLine())!=null)
{
System.out.println(itemset);
StringTokenizer st = new StringTokenizer(itemset);
FrequentItemset frequentitemset = new FrequentItemset();
for(i=0;i<st.countTokens()-1;i++)
frequentitemset.getItemset().add(st.nextToken());
support=st.nextToken().replaceAll("[()]","");
frequentitemset.setSupport(Integer.parseInt(support));
itemsetsize = frequentitemset.getItemset().size();
String first_item=frequentitemset.getItemset().get(0);
String targetitem="";
System.out.println("hi");
maxhashvalue = hashvalue(first_item);
System.out.println(maxhashvalue);
System.out.println("over");
// if the first item
if(AddedItemList.contains(first_item))
{
int firstitemhashtableno = ItemHashTable.get(first_item);
targetitem=first_item;
maxhashvalue = hashvalue(first_item);
System.out.println("hi");
System.out.println(maxhashvalue);
for(i=1;i<itemsetsize;i++)
{
String temp_item = frequentitemset.getItemset().get(i);
if(AddedItemList.contains(temp_item))
{
itemhashtableno = ItemHashTable.get(temp_item);
if(itemhashtableno==firstitemhashtableno)
{
if(hashvalue(temp_item)> maxhashvalue)
{
maxhashvalue=hashvalue(temp_item);
targetitem=temp_item;
}
}
else
{
System.out.println(frequentitemset.toString());
break;
}
}
else
{
System.out.println(frequentitemset.toString());
break;
}
}
if(i==itemsetsize)
{
int synopsisindex = hashvalue(synopsislist.get(firstitemhashtableno).get(0).getItem()) - hashvalue(targetitem)-1;
frequentitemset.setSupport(frequentitemset.getSupport()-(synopsislist.get(firstitemhashtableno).get(synopsisindex).getTimes()-synopsislist.get(firstitemhashtableno).get(synopsisindex).getOccurance()));
if(frequentitemset.getSupport()>=smin)
System.out.println(frequentitemset.toString());
}
}
else
{
System.out.println(frequentitemset.toString());
continue;
}
}
C Program T0,T1,T2 are static arrays here.
#include<stdio.h>
#include<jni.h>
#include"AuthorsFrequentItemsetMining.h"
#define uchar unsigned char
JNIEXPORT jint JNICALL Java_AuthorsFrequentItemsetMining_hashvalue(JNIEnv *env,jobject obj, jstring prompt)
{
int i;
unsigned f0, f1, f2;
const uchar *kp = (*env)->GetStringUTFChars(env,prompt,0);
for (i=-13, f0=f1=f2=0; *kp; ++kp) {
f0 += T0[i + *kp];
f1 += T1[i + *kp];
f2 += T2[i + *kp];
i += 45;
}
f0 %= 2913;
f1 %= 2913;
f2 %= 2913;
if (f1 == f0 && ++f1 >= 2913)
f1 = 0;
if (f2 == f0 && ++f2 >= 2913)
f2 = 0;
if (f1 == f2) {
if (++f2 >= 2913)
f2 = 0;
if (f2 == f0 && ++f2 >= 2913)
f2 = 0;
}
(*env)->ReleaseStringUTFChars(env,prompt,kp);
return (g[f0] + g[f1] + g[f2]) % 2368;
}
Header file created using javah
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class AuthorsFrequentItemsetMining */
#ifndef _Included_AuthorsFrequentItemsetMining
#define _Included_AuthorsFrequentItemsetMining
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: AuthorsFrequentItemsetMining
* Method: hashvalue
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_AuthorsFrequentItemsetMining_hashvalue
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
No correct solution
OTHER TIPS
The array T0[] or T1[] or T2[] doesn't have the items you are indexing so strangely, or the array g[] doesn't have 2913 items.
I can't see any reason why you should use JNI for this. It can be done perfectly well in Java, probably better actually.