gpt4 book ai didi

java - Android 应用程序中的 PorterStemmer 错误

转载 作者:行者123 更新时间:2023-12-02 03:25:54 24 4
gpt4 key购买 nike

我正在使用 Lucene 来提取词干。我在 Java 应用程序上进行了测试(主要是),它运行得很好。但是,在我的 Android 应用程序(在 onCreate 中)中它不起作用。有谁知道为什么?这是我在 onCreate 中的代码,在 onCreate 中旋转时出现错误:

import org.tartarus.snowball.ext.PorterStemmer;
import com.veryinteligent.jarvas.R;
import android.app.Activity;
import android.os.Bundle;

public class LuceneStemmer extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wordcommands);
String term = "obviously";
PorterStemmer stemmer = new PorterStemmer();
stemmer.setCurrent(term);
stemmer.stem();
System.out.println(stemmer.getCurrent());
}
}

import org.apache.lucene.analysis.en.EnglishAnalyzer;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.tartarus.snowball.ext.PorterStemmer;
import org.tartarus.snowball.ext.PortugueseStemmer;
import com.rmtheis.yandtran.language.Language;
import com.rmtheis.yandtran.translate.Translate;

public class TranslationTester {

public static void main(String[] args) {
String term = "Obviously";

PorterStemmer stemmer = new PorterStemmer();
stemmer.setCurrent(term);
stemmer.stem();
System.out.println(stemmer.getCurrent());
}
}

这是运行时遇到的堆栈跟踪。

08-11 19:32:55.455: E/dalvikvm(1148): Could not find class 'org.tartarus.snowball.ext.PorterStemmer', referenced from method com.veryinteligent.jarvas.activity.LuceneStemmer.onCreate
08-11 19:32:55.455: W/dalvikvm(1148): VFY: unable to resolve new-instance 2031 (Lorg/tartarus/snowball/ext/PorterStemmer;) in Lcom/veryinteligent/jarvas/activity/LuceneStemmer;
08-11 19:32:55.455: D/dalvikvm(1148): VFY: replacing opcode 0x22 at 0x000b
08-11 19:32:55.455: D/dalvikvm(1148): VFY: dead code 0x000d-001f in Lcom/veryinteligent/jarvas/activity/LuceneStemmer;.onCreate (Landroid/os/Bundle;)V
08-11 19:32:55.506: D/AndroidRuntime(1148): Shutting down VM
08-11 19:32:55.506: W/dalvikvm(1148): threadid=1: thread exiting with uncaught exception (group=0xb6ff14f0)
08-11 19:32:55.506: E/AndroidRuntime(1148): FATAL EXCEPTION: main
08-11 19:32:55.506: E/AndroidRuntime(1148): java.lang.NoClassDefFoundError: org.tartarus.snowball.ext.PorterStemmer
08-11 19:32:55.506: E/AndroidRuntime(1148): at com.veryinteligent.jarvas.activity.LuceneStemmer.onCreate(LuceneStemmer.java:18)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.os.Looper.loop(Looper.java:130)
08-11 19:32:55.506: E/AndroidRuntime(1148): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-11 19:32:55.506: E/AndroidRuntime(1148): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 19:32:55.506: E/AndroidRuntime(1148): at java.lang.reflect.Method.invoke(Method.java:507)
08-11 19:32:55.506: E/AndroidRuntime(1148): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-11 19:32:55.506: E/AndroidRuntime(1148): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-11 19:32:55.506: E/AndroidRuntime(1148): at dalvik.system.NativeStart.main(Native Method)

[更新]我发现我必须通过放置 libs 文件夹来导入我的文件。问题是我遇到错误“转换为 dalvik 格式失败,错误 1”。这是我的控制台消息:

[2016-08-13 01:43:12 - JARVAS] Dx 
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:672)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at sun.reflect.GeneratedMethodAccessor57.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:188)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:786)
at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:597)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:733)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:328)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:403)
at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
at org.eclipse.core.internal.resources.Project.build(Project.java:124)
at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1143)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:155)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:858)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:707)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1018)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1222)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:764)
at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
at com.android.dx.command.dexer.Main.processClass(Main.java:749)
... 32 more
[2016-08-13 01:43:12 - JARVAS] Dx 1 error; aborting
[2016-08-13 01:43:12 - JARVAS] Conversion to Dalvik format failed with error 1

我尝试了所有旧方法,有人知道新方法吗?

最佳答案

问题非常清楚,正如我们在堆栈跟踪中发现的那样:

java.lang.NoClassDefFoundError: org.tartarus.snowball.ext.PorterStemmer. 

在运行时检查您的类路径:这意味着您将 org.tartarus.snowball.ext.* 和相关类引入您的 Android 运行时环境。

因此,请检查是否缺少依赖项(.jar 文件)。对于 Lucene 版本 > 4.0 至 5.2.1,您应该包含 lucene-analyzers-common.jar 文件。

关于java - Android 应用程序中的 PorterStemmer 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38904949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com