I am trying to classify an instance using a .model file which I have created on the Weka GUI. It seems I have successfully classified the test instance, however, I am not sure whether I am able to successfully load my .model file and of the Stub compiler error.
I have tried to remove the extends AppCompatActivity
and if that makes any difference in the .model upload. It turns out that to use getAssets()
, the code must be in an activity. However, I an still unsure of whether the model has upload and the unusual compiler error. I have followed the basic framework of @davidmascharka's work on GitHub (he's also loading a WEKA model from assets), but mine does not compile.
Here's my code:
package com.example.owner.introductoryapplication;
import android.support.v7.app.AppCompatActivity;
import weka.classifiers.Classifier;
import weka.classifiers.rules.DecisionTable;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
import java.util.ArrayList;
public class Test extends AppCompatActivity {
public static void main(String[] args) {
Test test = new Test();
test.start();
}
public void start() {
//LOADS THE MODEL...------------------------------------------------------
String rootPath = "/assets/";
String fileName = "PGBD_DecisionTableUPD.model";
Classifier cls = null;
try {
//cls = (Classifier) weka.core.SerializationHelper.read(rootPath + fileName);
cls = (DecisionTable) weka.core.SerializationHelper.read(getAssets().open(fileName));
} catch (Exception e) {
e.printStackTrace();
}
}
}
And here's my error output:
Exception in thread "main" java.lang.RuntimeException: Stub!
at android.content.Context.<init>(Context.java:67)
at android.content.ContextWrapper.<init>(ContextWrapper.java:30)
at android.view.ContextThemeWrapper.<init>(ContextThemeWrapper.java:40)
at android.app.Activity.<init>(Activity.java:643)
at android.support.v4.app.SupportActivity.<init>(ComponentActivity.java:46)
at android.support.v4.app.FragmentActivity.<init>(FragmentActivity.java:68)
at android.support.v7.app.AppCompatActivity.<init>(AppCompatActivity.java:62)
at com.example.owner.introductoryapplication.Test.<init>(Test.java:13)
at com.example.owner.introductoryapplication.Test.main(Test.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Process finished with exit code 1
I expect the program to at least compile! I have absolutely no clue why it's not. I tried switching the order of my dependencies, hoping that would make a difference, but to no luck.
Any ideas?
Thanks in advance.
This may have been covered before, but
weka.jar
only allows for Stub implementations. Essentially, you must configure the run setting to "app" instead of a specific file.If you want to see how a specific file works, then you can use the
debug
option for your app.