坏
坏蛋是我
Unregistered / Unconfirmed
GUEST, unregistred user!
////////////////////////////////////////////////////////////////////////////
// 声 明
// 本人对JAVA七窍已通六窍,在加上时间紧急,所以来此求助!谢谢!
// 您可以从这里下载整个工程: http://huatao.xiloo.com/GoleDic.rar
////////////////////////////////////////////////////////////////////////////
熟悉JNI的朋友过来看一下,FindClass问题!谢谢!
JAVA代码如下:
//Index.java的代码!
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.DateField;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.cn.*;
import org.apache.lucene.analysis.cn.ChineseAnalyzer;
import java.util.Hashtable;
import java.util.Date;
import java.io.File;
import java.io.Reader;
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.String;
import javax.swing.JOptionPane;
class FileDocument
{
public staticdo
cumentdo
cument(File f)
throws java.io.FileNotFoundException
{
do
cumentdo
c = newdo
cument();
do
c.add(Field.Text("path", f.getPath()));
do
c.add(Field.Keyword("modified",
DateField.timeToString(f.lastModified())));
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
do
c.add(Field.Text("contents", reader));
returndo
c;
}
private FileDocument() {}
}
public class Index
{
public static void main(String args[])
{
File TxtFile;
String AppPath = System.getProperty("user.dir")+"//";
String ResultFullPath = AppPath + "result.txt";
TextPath = args[0];
IndexPath = args[1];
JOptionPane.showMessageDialog(null, TextPath+IndexPath, "alert", JOptionPane.ERROR_MESSAGE);
try
{
IndexWriter awriter = new IndexWriter(IndexPath, new StandardAnalyzer(), true);
indexDocs(awriter, new File(TextPath));
awriter.optimize();
awriter.close();
} catch (Exception e)
{
;;
}
}
public static void indexDocs(IndexWriter writer, File file) throws Exception
{
if (file.isDirectory())
{
String[] files = file.list();
for (int i = 0;
i < files.length;
i++)
indexDocs(writer, new File(file, files));
} else
{
System.out.println("adding " + file);
writer.addDocument(FileDocument.Document(file));
}
}
}
编译通过, 命令行执行也通过!
但是当我在C++ Builder里面调用时:
#define MAIN_CLASS "Index"
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
char infor[255];
jmethodID mid;
jclass cls;
int result;
jint square;
jboolean not;
if(MainForm->jvm == NULL || MainForm->env == NULL) return;
cls = MainForm->env->FindClass(MAIN_CLASS);
if( cls != 0 )
{
mid = MainForm->env->GetStaticMethodID(cls, "main", "([Ljava/lang/StringV");
if( mid!= 0 )
{
int i= 1, ret;
jstring TxtFileName, IndexPath;
jobjectArray args;
char *WinStr;
WinStr = "E:////GoleDic////text////";
TxtFileName = WindowsTojstring(MainForm->env, WinStr);
WinStr = "E:////GoleDic////index////";
IndexPath = WindowsTojstring(MainForm->env, WinStr);
args= MainForm->env->NewObjectArray(2, MainForm->env->FindClass("java/lang/String"), 0);
MainForm->env->SetObjectArrayElement(args, 0, TxtFileName);
MainForm->env->SetObjectArrayElement(args, 1, IndexPath);
MainForm->env->CallStaticVoidMethod(cls, mid, args);
}
}
return;
}
MainForm->env->FindClass(MAIN_CLASS)找不到Index这个类!
然后我把JAVA的代码改成:
...
try
{
/*
IndexWriter awriter = new IndexWriter(IndexPath, new StandardAnalyzer(), true);
indexDocs(awriter, new File(TextPath));
awriter.optimize();
awriter.close();
*/
} catch (Exception e)
{
;;
}
...
MainForm->env->FindClass(MAIN_CLASS)就能找到Index这个类!
这是为什么?请指教!
// 声 明
// 本人对JAVA七窍已通六窍,在加上时间紧急,所以来此求助!谢谢!
// 您可以从这里下载整个工程: http://huatao.xiloo.com/GoleDic.rar
////////////////////////////////////////////////////////////////////////////
熟悉JNI的朋友过来看一下,FindClass问题!谢谢!
JAVA代码如下:
//Index.java的代码!
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.DateField;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.cn.*;
import org.apache.lucene.analysis.cn.ChineseAnalyzer;
import java.util.Hashtable;
import java.util.Date;
import java.io.File;
import java.io.Reader;
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.String;
import javax.swing.JOptionPane;
class FileDocument
{
public staticdo
cumentdo
cument(File f)
throws java.io.FileNotFoundException
{
do
cumentdo
c = newdo
cument();
do
c.add(Field.Text("path", f.getPath()));
do
c.add(Field.Keyword("modified",
DateField.timeToString(f.lastModified())));
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
do
c.add(Field.Text("contents", reader));
returndo
c;
}
private FileDocument() {}
}
public class Index
{
public static void main(String args[])
{
File TxtFile;
String AppPath = System.getProperty("user.dir")+"//";
String ResultFullPath = AppPath + "result.txt";
TextPath = args[0];
IndexPath = args[1];
JOptionPane.showMessageDialog(null, TextPath+IndexPath, "alert", JOptionPane.ERROR_MESSAGE);
try
{
IndexWriter awriter = new IndexWriter(IndexPath, new StandardAnalyzer(), true);
indexDocs(awriter, new File(TextPath));
awriter.optimize();
awriter.close();
} catch (Exception e)
{
;;
}
}
public static void indexDocs(IndexWriter writer, File file) throws Exception
{
if (file.isDirectory())
{
String[] files = file.list();
for (int i = 0;
i < files.length;
i++)
indexDocs(writer, new File(file, files));
} else
{
System.out.println("adding " + file);
writer.addDocument(FileDocument.Document(file));
}
}
}
编译通过, 命令行执行也通过!
但是当我在C++ Builder里面调用时:
#define MAIN_CLASS "Index"
void __fastcall TMainForm::Button1Click(TObject *Sender)
{
char infor[255];
jmethodID mid;
jclass cls;
int result;
jint square;
jboolean not;
if(MainForm->jvm == NULL || MainForm->env == NULL) return;
cls = MainForm->env->FindClass(MAIN_CLASS);
if( cls != 0 )
{
mid = MainForm->env->GetStaticMethodID(cls, "main", "([Ljava/lang/StringV");
if( mid!= 0 )
{
int i= 1, ret;
jstring TxtFileName, IndexPath;
jobjectArray args;
char *WinStr;
WinStr = "E:////GoleDic////text////";
TxtFileName = WindowsTojstring(MainForm->env, WinStr);
WinStr = "E:////GoleDic////index////";
IndexPath = WindowsTojstring(MainForm->env, WinStr);
args= MainForm->env->NewObjectArray(2, MainForm->env->FindClass("java/lang/String"), 0);
MainForm->env->SetObjectArrayElement(args, 0, TxtFileName);
MainForm->env->SetObjectArrayElement(args, 1, IndexPath);
MainForm->env->CallStaticVoidMethod(cls, mid, args);
}
}
return;
}
MainForm->env->FindClass(MAIN_CLASS)找不到Index这个类!
然后我把JAVA的代码改成:
...
try
{
/*
IndexWriter awriter = new IndexWriter(IndexPath, new StandardAnalyzer(), true);
indexDocs(awriter, new File(TextPath));
awriter.optimize();
awriter.close();
*/
} catch (Exception e)
{
;;
}
...
MainForm->env->FindClass(MAIN_CLASS)就能找到Index这个类!
这是为什么?请指教!