问题
I'm trying to work with pdfbox and groovy together. I wrote a code that takes some information in a format of string and creates a pdf document with that info. I want to integrate this code to an android app I'm creating.
I ran the code in intellij IDEA and it works very well, but when I try to run the code in Android Studio, I get a MissingPropertyException in some part of the code which works perfectly not on Android Studio. The code in this part use a method called getWidth()
from the PDRectangle class. I know for sure that there is a method like this in this specific class. So why do I still keep getting this MissingMethodExceptions?
The error output:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.silverfix.groovytestapp, PID: 5723
groovy.lang.MissingMethodException: No signature of method: org.apache.pdfbox.pdmodel.common.PDRectangle.getWidth() is applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), with(groovy.lang.Closure), getClass()
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at dgdlib.components.FormMetaHolder$_setupSizes_closure1.doCall(FormMetaHolder.groovy:41)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3170)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3140)
at org.codehaus.groovy.runtime.dgm$66.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at dgdlib.components.FormMetaHolder.setupSizes(FormMetaHolder.groovy:26)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at dgdlib.DGDExecuter.initialize(DGDExecuter.groovy:48)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at dgdlib.DGDExecuter.execute(DGDExecuter.groovy:36)
at com.silverfix.groovytestapp.MainActivity$1.onClick(MainActivity.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
Here is the activity's code which I run the groovy code in:
package com.silverfix.groovytestapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.ArrayList;
import java.util.List;
import dgdlib.Constants;
import dgdlib.DGDExecuter;
import dgdlib.components.entities.DGObject;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.create_doc);
// DGObject class represents a specific object which has its own attributes that needs to be inserted to the pdf
final List<DGObject> goods = new ArrayList();
DGObject object = new DGObject("3456", "2.3", "Packing Group", "Description", "Qunatity Type"
,"Packing Instructions", "Authorization");
goods.add(object);
final Bundle properties = new Bundle();
// Insert some information to this bundle
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DGDExecuter().execute(MainActivity.this, properties, goods);
}
});
}
}
The part in the groovy code which fails in runtime:
PDAnnotationWidget widget = field.getWidgets().get(0)
PDRectangle rectangle = widget.getRectangle()
float width = rectangle.getWidth()
What is the problem here?
Here is an image of the project hierarchy: https://i.gyazo.com/70a3683f6f78d7b02d63defc4e7b2c2c.png
And here is an image of the class PDRectangle, specifically the part where the method getWidth()
is:
https://i.gyazo.com/5086b7536c690005127b76fff41cae83.png
来源:https://stackoverflow.com/questions/41519977/missingmethodexception-in-groovy