【问题标题】:the call to a function does not correspond to any overload of对函数的调用不对应于任何重载
【发布时间】:2019-03-25 11:07:24
【问题描述】:

我正在开发一个 java 库来管理 Crystal Report 中不同种类的条形码。 Crystal Report 为 Eclipse 提供了一个 sdk,在一个新项目中,有一个库来开发 ERP 和 CR 之间的集成。其中一个库管理条形码,但它是一个糟糕的库,因为我只能管理一种条形码。我找到了实现 UFL 的文档。该文档提供了一个简单的示例,感谢我编写了一些类来管理三种条形码,但是有一些带有两个参数的水晶报表功能,并且该示例没有说明如何正确实现。我试图开发新的类来管理这种函数,但我总是收到这条错误消息:“对函数的调用不对应于‘函数名’的任何重载”。

对于这个函数,我尝试只传递一个参数并且应用程序运行良好。我对方法进行了重载,传递了两个参数,但总是收到相同的错误消息。

这是我的代码的一部分

public final FormulaValue evaluate(FormulaValueReference[] arguments)
     throws FormulaFunctionCallException
  {

       StringValue dataStringArg = (StringValue)arguments[0].getFormulaValue();
       StringValue opzArg =(StringValue)arguments[1].getFormulaValue();

     String dataString = dataStringArg.getString();
     String opz=opzArg.getString();



    String returnVal = doTranslation(dataString,opz);

    return StringValue.fromString(returnVal);
   }

  protected abstract String translate(String inputData,String opz)
   throws InvalidBarcodeDataException;


public class CodeEAN13
  extends CodeEAN13Base
{


   public String getIdentifier()
   {
    return "barcodeean13";
  }

protected String translate(String inputData, String opz) throws InvalidBarcodeDataException {
    Integer checkDigitSubtotal;
.....
}

我只是显示带有那种条形码的报告。 CodeEAN13 类应该运行一个算法来计算条形码字体的字符串。

这是程序运行时库中的代码并显示在堆栈跟踪中。对于 stracktrace 的每一行,我都放置了相应的代码。

//com.crystaldecisions.reports.formulas.FormulaService.compile(SourceFile:347)

public void compile(FormulaDefinitionBase paramFormulaDefinitionBase, FormulaContext paramFormulaContext)
    throws FormulaException
  {
    if (paramFormulaDefinitionBase == null) {
      throw new NullPointerException("A formula must be given.");
    }
    paramFormulaDefinitionBase.getFormulaInfo().a(paramFormulaContext);
  }

//com.crystaldecisions.reports.formulas.FormulaInfo.a(SourceFile:570)

void a(FormulaContext paramFormulaContext)
    throws FormulaException
  {
    if (this.jdField_try)
    {
      this.o = true;

      throw new FormulaException("JRC00000433", "", FormulaResources.a(), "RecursiveCompileDetected", this);
    }
    this.o = false;
    if (paramFormulaContext == null) {
      throw new NullPointerException("A formula context must be given.");
    }
    try
    {
      this.jdField_try = true;
      jdMethod_if(paramFormulaContext);
      this.t = this.jdField_long.getFormulaValueType();
      this.jdField_do.a();//(SourceFile:570)
    }
    catch (FormulaException localFormulaException)
    {
      if ((localFormulaException.getResourceKey().equals("RecursiveCompileDetected")) && (this.o)) {
        throw new FormulaException("JRC00000434", "", FormulaResources.a(), "RecursionNotAllowed", null, localFormulaException);
      }
      throw localFormulaException;
    }
    finally
    {
      this.jdField_try = false;
      jdMethod_if();
    }
  }

//com.crystaldecisions.reports.formulas.r.a(SourceFile:90)
public void a()
    throws FormulaException
  {
    FormulaInfo localFormulaInfo = this.a.getFormulaInfo();
    FormulaDefinitionBase localFormulaDefinitionBase = this.a.getFormula();
    String str1 = "Formula";
    String str2 = "";
    if ((localFormulaDefinitionBase instanceof CustomFunctionDefinition))
    {
      str1 = "Custom function";
      str2 = "'";
    }
    if (if.isDebugEnabled()) {
      if.debug("Compiling " + StringUtil.toLowerCaseEng(str1) + " " + str2 + localFormulaDefinitionBase.getFormulaForm() + str2 + "...");
    }
    localFormulaInfo.invalidate();
    try
    {
      ExpressionNode localExpressionNode = o.a(this.a).a();
      localExpressionNode = this.jdField_do.jdMethod_void(localExpressionNode);//(SourceFile:90)
      localExpressionNode = this.jdField_for.c(localExpressionNode);
      localFormulaInfo.a(localExpressionNode);

      localFormulaDefinitionBase.formulaInfoUpdated();
      if (if.isInfoEnabled()) {
        if.info(str1 + " " + str2 + localFormulaDefinitionBase.getFormulaForm() + str2 + " compiled.");
      }
    }
    catch (FormulaException localFormulaException)
    {
      if (if.isInfoEnabled()) {
        if.info(str1 + " " + str2 + localFormulaDefinitionBase.getFormulaForm() + str2 + " did not compile: " + localFormulaException);
      }
      localFormulaInfo.invalidate();

      throw localFormulaException;
    }
  }
}
//com.crystaldecisions.reports.formulas.c.void(SourceFile:70)
 public ExpressionNode jdMethod_void(ExpressionNode paramExpressionNode)
    throws FormulaException
  {
    ExpressionNode localExpressionNode = paramExpressionNode;

    this.jdField_int = 0;
    this.jdField_for = 0;

    FormulaDefinitionBase localFormulaDefinitionBase = this.a.getFormula();
    FormulaInfo localFormulaInfo = this.a.getFormulaInfo();

    localExpressionNode = jdMethod_do(localExpressionNode);//(SourceFile:70)

    FormulaValueType localFormulaValueType = a(localFormulaDefinitionBase, localFormulaInfo, localExpressionNode);
    if ((localExpressionNode != null) && (!localFormulaValueType.equals(localExpressionNode.getFormulaValueType())))
    {
      localExpressionNode = a(localExpressionNode, localFormulaValueType);
      if ((!new) && (!localExpressionNode.getFormulaValueType().equals(localFormulaValueType))) {
        throw new AssertionError("Coercion failed!!! This should never happen.");
      }
    }
    localFormulaInfo.a(localFormulaValueType);

    return localExpressionNode;
  }

  //com.crystaldecisions.reports.formulas.j.do(SourceFile:74)
  final ExpressionNode jdMethod_do(ExpressionNode paramExpressionNode)
    throws FormulaException
  {
    try
    {
      return a(paramExpressionNode);//(SourceFile:74)
    }
    catch (StackOverflowError localStackOverflowError)
    {
      throw new FormulaException("JRC00000461", "", FormulaResources.a(), "StackOverflow", this.a);
    }
  }

  //com.crystaldecisions.reports.formulas.j.a(SourceFile:250)
  ExpressionNode a(ExpressionNode paramExpressionNode)
    throws FormulaException
  {
    if (paramExpressionNode == null) {
      return null;
    }
    switch (paramExpressionNode.jdField_for.value())
    {
        ......
        case 30: 
      return jdMethod_for((MultiOperatorNode)paramExpressionNode);


//com.crystaldecisions.reports.formulas.c.for(SourceFile:1225)
 ExpressionNode jdMethod_for(MultiOperatorNode paramMultiOperatorNode)
    throws FormulaException
  {
    int i = paramMultiOperatorNode.size();
    if (i == 0) {
      return null;
    }
    for (int j = 0; j < i; j++)
    {
      ExpressionNode localExpressionNode = a(paramMultiOperatorNode.getOperand(j));//(SourceFile:1225)
      if (localExpressionNode == null) {
        return null;
      }
      paramMultiOperatorNode.setOperand(j, localExpressionNode);
    }
    paramMultiOperatorNode.jdField_try = paramMultiOperatorNode.getOperand(i - 1).jdField_try;

    return paramMultiOperatorNode;
  } 

  //com.crystaldecisions.reports.formulas.j.a(SourceFile:295)
  case 8: 
      return a((FunctionNode)paramExpressionNode);


//com.crystaldecisions.reports.formulas.j.a(SourceFile:3148)
 ExpressionNode a(FunctionNode paramFunctionNode)
    throws FormulaException
  {
    int i = paramFunctionNode.size();
    ExpressionNode[] arrayOfExpressionNode = ArrayPool.a(i, this.a);
    try
    {
      for (int j = 0; j < i; j++)
      {
        ExpressionNode localExpressionNode2 = a(paramFunctionNode.get(j), arrayOfExpressionNode);
        if (localExpressionNode2 == null) {
          return null;
        }
        arrayOfExpressionNode[j] = localExpressionNode2;
      }
      return a(paramFunctionNode, arrayOfExpressionNode);//(SourceFile:3148)
    }
    finally
    {
      ArrayPool.a(arrayOfExpressionNode, this.a);
    }
  }

 //com.crystaldecisions.reports.formulas.c.a(SourceFile:1809)



//com.crystaldecisions.reports.formulas.j.a(SourceFile:3507)
 FormulaException a(String paramString1, String paramString2, String paramString3, String[] paramArrayOfString, ExpressionNode paramExpressionNode)
  {
    return a(paramString1, paramString2, paramString3, paramArrayOfString, null, paramExpressionNode);
  }

  //com.crystaldecisions.reports.formulas.j.a(SourceFile:3528)
  FormulaException a(String paramString1, String paramString2, String paramString3, String[] paramArrayOfString, Throwable paramThrowable, ExpressionNode paramExpressionNode)
  {
    return new FormulaException(paramString1, paramString2,FormulaResources.a(), paramString3, paramArrayOfString, paramThrowable, this.a, paramExpressionNode);//(SourceFile:3528)
  }


   public FormulaException(String paramString1, String paramString2, CrystalResourcesFactory paramCrystalResourcesFactory, String paramString3, String[] paramArrayOfString, Throwable paramThrowable, FormulaEnvironment paramFormulaEnvironment, ExpressionNode paramExpressionNode)
  {
    super(paramString1, paramString2, paramCrystalResourcesFactory, paramString3, paramArrayOfString, paramThrowable);

    a(paramFormulaEnvironment, paramExpressionNode);
  }

【问题讨论】:

  • 翻译的实现不应该有@Override注解吗?
  • 我曾尝试使用 @Override 注释,但没有任何改变。
  • 如果不急的话我稍后再看,如果可以的话,目前正在忙。
  • 非常感谢您,当您可以从您的承诺。您的帮助将不胜感激,因为我不知道该怎么办了。
  • 我看了看,您的代码似乎不完整。最好在这里发布尽可能多的内容,以便其他用户重现您的问题。如果您需要帮助,请查看stackoverflow.com/help,并在您更新完这些详细信息后告诉我。

标签: java crystal-reports


【解决方案1】:

这是完整的代码

import com.crystaldecisions.reports.formulas.FormulaFunction;
import com.crystaldecisions.reports.formulas.FormulaFunctionLibrary;



 public class BarcodeLibrary
   implements FormulaFunctionLibrary
 {
   private final FormulaFunction[] functionArray = {new Code39(), new Code39Ascii(), new CodeI2of5(), new Code2of5()
                                                    ,new CodeC128SetA(),new CodeEAN13()};

   public FormulaFunction getFunction(int functionNumber)
   {
     return this.functionArray[functionNumber];
   }

   public int size()
   {
    return this.functionArray.length;
  }
 }

*************************************************************************
import com.crystaldecisions.reports.common.CrystalResourcesFactory;
import com.crystaldecisions.reports.common.value.FormulaValue;
import com.crystaldecisions.reports.common.value.FormulaValueType;
import com.crystaldecisions.reports.common.value.StringValue;
import com.crystaldecisions.reports.formulas.FormulaFunction;
import com.crystaldecisions.reports.formulas.FormulaFunctionArgumentDefinition;
import com.crystaldecisions.reports.formulas.FormulaFunctionCallException;
import com.crystaldecisions.reports.formulas.FormulaValueReference;
import com.crystaldecisions.reports.formulas.SimpleFormulaFunctionArgumentDefinition;

public abstract class CodeEAN13Base
   implements FormulaFunction
 {
   FormulaFunctionArgumentDefinition[] myArguments = { SimpleFormulaFunctionArgumentDefinition.string };

protected CrystalResourcesFactory resCrystal;



  public CodeEAN13Base()
   {
     this.resCrystal = new CrystalResourcesFactory("Messages");

   }


  protected final String doTranslation(String inputData,String opz)

   {
    String returnVal = "";

     returnVal = returnVal + translateCharWrapper(inputData,opz);



    return returnVal;
   }


   @Override
   public final FormulaValue evaluate(FormulaValueReference[] arguments)
     throws FormulaFunctionCallException
  {

       StringValue dataStringArg = (StringValue)arguments[0].getFormulaValue();
       StringValue opzArg =(StringValue)arguments[1].getFormulaValue();

     String dataString = dataStringArg.getString();
     String opz=opzArg.getString();



    String returnVal = doTranslation(dataString,opz);

    return StringValue.fromString(returnVal);
   }

   @Override
   public final FormulaFunctionArgumentDefinition[] getArguments()
  {
     return this.myArguments;
  }

 @Override  
public final FormulaValueType getReturnType()
  {
     return FormulaValueType.string;
   }


   protected abstract String translate(String inputData,String opz)
   throws InvalidBarcodeDataException;

//protected abstract String translateChar(String inputData)
//throws InvalidBarcodeDataException;

 // private String translateCharWrapper(String inputData)
   private String translateCharWrapper(String inputData,String opz)
  {
     String returnString;

     try
    {
        // returnString = translateChar(inputData);
      returnString = translate(inputData,opz);
     } catch (InvalidBarcodeDataException e) {
      returnString = "";
     }

    return returnString;
  }

   @Override
   public void validateArgumentValues(FormulaValueReference[] arguments)
     throws FormulaFunctionCallException
   {}
 }

*************************************************************************
public class CodeEAN13
  extends CodeEAN13Base
{

    protected String opz;



   @Override
   public String getIdentifier()
   {
    return "barcodeean13";
  }



  private static String oddBar(String code) {

        return String.valueOf((char)(65+Integer.parseInt(code)));

    }

  private static String evenBar(String code) {

        return String.valueOf((char)(75+Integer.parseInt(code)));

    }





@Override
protected String translate(String inputData, String opz) throws InvalidBarcodeDataException {
    // TODO Auto-generated method stub
    Integer checkDigitSubtotal;
  String checkDigit;
      String temp = null;
      String code=inputData;
      String azalea_EAN13 = null;
      Object opzM=opz;

      if(!opzM.equals(null)) {
       code=code+opzM;
      }

      //Calculate the EAN-13 check digit.

      checkDigitSubtotal=3*(Integer.parseInt(code.substring(1, 2))+Integer.parseInt(code.substring(3, 4))+Integer.parseInt(code.substring(5, 6))
                           +Integer.parseInt(code.substring(7, 8))+Integer.parseInt(code.substring(9, 10))
                           +Integer.parseInt(code.substring(code.length()-1)));


  checkDigitSubtotal=checkDigitSubtotal+(Integer.parseInt(code.substring(0,1))+Integer.parseInt(code.substring(2, 3))
                                       +Integer.parseInt(code.substring(4, 5))+Integer.parseInt(code.substring(6, 7))
                                       +Integer.parseInt(code.substring(8, 9))+Integer.parseInt(code.substring(10, 11)));

  checkDigit=String.valueOf(300-checkDigitSubtotal);
  checkDigit=checkDigit.substring(checkDigit.length()-1);



 // Begin building the output string with the 1st character's human-readable, L guard bars & odd parity of 1st digit
   temp=(char)(194+Integer.parseInt(code.substring(0,1)))+"x"+oddBar(code.substring(1, 2));  

  // Build the remainder of left half of symbol's parity is based on 1st digit
   switch (code.substring(0,1)) {
   case "0":
      {
         temp=temp+oddBar(code.substring(2, 3));
         temp=temp+oddBar(code.substring(3, 4));
         temp=temp+oddBar(code.substring(4, 5));
         temp=temp+oddBar(code.substring(5, 6));
         temp=temp+oddBar(code.substring(6, 7));         
      }
    break;
   case "1":
      {
          temp=temp+oddBar(code.substring(2, 3)); 
          temp=temp+evenBar(code.substring(3, 4));
          temp=temp+oddBar(code.substring(4, 5));
          temp=temp+evenBar(code.substring(5, 6));
          temp=temp+evenBar(code.substring(6, 7));
      }
      break;
   case "2":
   {
       temp=temp+oddBar(code.substring(2, 3));
       temp=temp+evenBar(code.substring(3, 4));
       temp=temp+evenBar(code.substring(4, 5));
       temp=temp+oddBar(code.substring(5, 6));
       temp=temp+evenBar(code.substring(6, 7));
   }
   break;
   case "3":
   {
       temp=temp+oddBar(code.substring(2, 3));
       temp=temp+evenBar(code.substring(3, 4));
       temp=temp+evenBar(code.substring(4, 5));
       temp=temp+evenBar(code.substring(5, 6));
       temp=temp+oddBar(code.substring(6, 7));
   }
    break;
   case "4":
   {
       temp=temp+evenBar(code.substring(2, 3));
       temp=temp+oddBar(code.substring(3, 4));
       temp=temp+oddBar(code.substring(4, 5));
       temp=temp+evenBar(code.substring(5, 6));
       temp=temp+evenBar(code.substring(6, 7));

   }
   break;
   case "5":
   {
       temp=temp+evenBar(code.substring(2, 3));
       temp=temp+evenBar(code.substring(3, 4));
       temp=temp+oddBar(code.substring(4, 5));
       temp=temp+oddBar(code.substring(5, 6));
       temp=temp+evenBar(code.substring(6, 7));

   }
   break;
   case "6":
   {
       temp=temp+evenBar(code.substring(2, 3));
       temp=temp+evenBar(code.substring(3, 4));
       temp=temp+evenBar(code.substring(4, 5));
       temp=temp+oddBar(code.substring(5, 6));
       temp=temp+oddBar(code.substring(6, 7));

   }
   break;
   case "7":
   {
       temp=temp+evenBar(code.substring(2, 3));
       temp=temp+oddBar(code.substring(3, 4));
       temp=temp+evenBar(code.substring(4, 5));
       temp=temp+oddBar(code.substring(5, 6));
       temp=temp+evenBar(code.substring(6, 7));



   }
   break;
   case "8":
   {
       temp=temp+evenBar(code.substring(2, 3));
       temp=temp+oddBar(code.substring(3, 4));
       temp=temp+evenBar(code.substring(4, 5));
       temp=temp+evenBar(code.substring(5, 6));
       temp=temp+oddBar(code.substring(6, 7));

   }
   break;
   case "9":
   {
       temp=temp+evenBar(code.substring(2, 3));
       temp=temp+evenBar(code.substring(3, 4));
       temp=temp+oddBar(code.substring(4, 5));
       temp=temp+evenBar(code.substring(5, 6));
       temp=temp+oddBar(code.substring(6, 7));

   }
   break;

    default:
   }

////Add the center guard bars & the build right half of symbol using set C (0-9)

    return azalea_EAN13;
   }


 }


【讨论】:

    【解决方案2】:

    部分日志:

    1922 [TSLVReader #1] DEBUG com.crystaldecisions.reports.formulas.Compiler  - Compiling formula {@ean13}...
    1922 [TSLVReader #1] INFO com.crystaldecisions.reports.formulas.Compiler  - Formula {@ean13} did not compile: com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
    the call to a function does not correspond to any overload of barcodeean13.
    1922 [TSLVReader #1] WARN com.crystaldecisions.reports.reportdefinition.ReportDefinition  - com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas  '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
    the call to a function does not correspond to any overload of barcodeean13.
    1923 [TSLVReader #1] ERROR com.crystaldecisions.reports.dataengine  - Formula error: recompile formulas failed
    com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas  '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
    the call to a function does not correspond to any overload of barcodeean13.
        at com.crystaldecisions.reports.formulas.j.a(SourceFile:3528)
        at com.crystaldecisions.reports.formulas.j.a(SourceFile:3507)
        at com.crystaldecisions.reports.formulas.c.a(SourceFile:1809)
        at com.crystaldecisions.reports.formulas.j.a(SourceFile:3148)
        at com.crystaldecisions.reports.formulas.j.a(SourceFile:295)
        at com.crystaldecisions.reports.formulas.c.for(SourceFile:1225)
        at com.crystaldecisions.reports.formulas.j.a(SourceFile:250)
        at com.crystaldecisions.reports.formulas.j.do(SourceFile:74)
        at com.crystaldecisions.reports.formulas.c.void(SourceFile:70)
        at com.crystaldecisions.reports.formulas.r.a(SourceFile:90)
        at com.crystaldecisions.reports.formulas.FormulaInfo.a(SourceFile:570)
        at com.crystaldecisions.reports.formulas.FormulaService.compile(SourceFile:347)
    

    【讨论】:

      【解决方案3】:
      1922 [TSLVReader #1] DEBUG com.crystaldecisions.reports.formulas.Compiler  - Compiling formula {@ean13}...
      1922 [TSLVReader #1] INFO com.crystaldecisions.reports.formulas.Compiler  - Formula {@ean13} did not compile: com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
      the call to a function does not correspond to any overload of barcodeean13.
      1922 [TSLVReader #1] WARN com.crystaldecisions.reports.reportdefinition.ReportDefinition  - com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas  '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
      the call to a function does not correspond to any overload of barcodeean13.
      1923 [TSLVReader #1] ERROR com.crystaldecisions.reports.dataengine  - Formula error: recompile formulas failed
      com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas  '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
      the call to a function does not correspond to any overload of barcodeean13.
          at com.crystaldecisions.reports.formulas.j.a(SourceFile:3528)
          at com.crystaldecisions.reports.formulas.j.a(SourceFile:3507)
          at com.crystaldecisions.reports.formulas.c.a(SourceFile:1809)
          at com.crystaldecisions.reports.formulas.j.a(SourceFile:3148)
          at com.crystaldecisions.reports.formulas.j.a(SourceFile:295)
          at com.crystaldecisions.reports.formulas.c.for(SourceFile:1225)
          at com.crystaldecisions.reports.formulas.j.a(SourceFile:250)
          at com.crystaldecisions.reports.formulas.j.do(SourceFile:74)
          at com.crystaldecisions.reports.formulas.c.void(SourceFile:70)
          at com.crystaldecisions.reports.formulas.r.a(SourceFile:90)
          at com.crystaldecisions.reports.formulas.FormulaInfo.a(SourceFile:570)
          at com.crystaldecisions.reports.formulas.FormulaService.compile(SourceFile:347)
      

      stacktrace 告诉你你需要知道什么,但是我无法提供更具体的信息,因为 Crystal Reports 似乎是付费的,而且他们不提供文档(至少是免费的),所以我无法查看罐子。
      无论如何,这个 sn-p 会告诉您您需要知道的大部分内容:

      1923 [TSLVReader #1] ERROR com.crystaldecisions.reports.dataengine  - Formula error: recompile formulas failed
      com.crystaldecisions.reports.formulas.FormulaException: Exception in the formulas  '{@ean13}' a 'BarcodeEAN13('412345678901','567')':
      the call to a function does not correspond to any overload of barcodeean13.
          at com.crystaldecisions.reports.formulas.j.a(SourceFile:3528)
      

      这一行:

      com.crystaldecisions.reports.formulas.FormulaException  
      

      告诉您抛出的异常来自 Crystal Reports 源代码,而不是 Java 特定的错误。因此如果可以的话,您应该查阅文档(如果您有权访问)或检查源代码以查看导致此问题抛出的条件。如果您不确定如何操作,可以在问题中添加一些此类信息,我或其他人可以尝试提供帮助。

      at com.crystaldecisions.reports.formulas.j.a(SourceFile:3528)
      

      括号中的部分告诉您在哪里查找异常的来源,SourceFile,可能但不一定在第 3528 行。此行号在实践中可能不同,特别是如果您正在查看的代码是反编译的,因此,如果事情没有按预期排列,您可能需要四处寻找确切的路线。

      很遗憾,如果没有文档或源代码,将很难为您提供进一步的帮助。

      【讨论】:

        【解决方案4】:

        问题在于这句话:

        FormulaFunctionArgumentDefinition[] myArguments = {SimpleFormulaFunctionArgumentDefinition.string };
        

        参数的正确配置是:

        FormulaFunctionArgumentDefinition[] myArguments = { SimpleFormulaFunctionArgumentDefinition.string,SimpleFormulaFunctionArgumentDefinition.string };
        

        显然在我的 Crystal Report 公式中有两种 String 类型或一种 String 类型,取决于公式。 下面是解决带有两个参数的条形码函数的 UFL 的完整代码。此代码为 Crystal Report 设置 UFL 库。

        import com.crystaldecisions.reports.common.CrystalResourcesFactory;
        import com.crystaldecisions.reports.common.value.FormulaValue;
        import com.crystaldecisions.reports.common.value.FormulaValueType;
        
        import com.crystaldecisions.reports.common.value.StringValue;
        import com.crystaldecisions.reports.formulas.FormulaFunction;
        import com.crystaldecisions.reports.formulas.FormulaFunctionArgumentDefinition;
        import com.crystaldecisions.reports.formulas.FormulaFunctionCallException;
        import com.crystaldecisions.reports.formulas.FormulaValueReference;
        import com.crystaldecisions.reports.formulas.SimpleFormulaFunctionArgumentDefinition;
        
        public abstract class CodeEAN13Base
           implements FormulaFunction
         {
           FormulaFunctionArgumentDefinition[] myArguments = { SimpleFormulaFunctionArgumentDefinition.string,SimpleFormulaFunctionArgumentDefinition.string };
        
        protected CrystalResourcesFactory resCrystal;
        
        
        
          public CodeEAN13Base()
           {
             this.resCrystal = new CrystalResourcesFactory("Messages");
        
           }
        
        
          protected final String doTranslation(String inputData,String opz)
         // protected final String doTranslation(String inputData)
           {
            String returnVal = "";
        
           //  returnVal = returnVal + translateCharWrapper(inputData);
             returnVal = returnVal + translateCharWrapper(inputData,opz);
        
        
            return returnVal;
           }
        
        
        
           @Override
           public final FormulaValue evaluate(FormulaValueReference[] arguments)
             throws FormulaFunctionCallException
          {
        
               StringValue dataStringArg = (StringValue)arguments[0].getFormulaValue();
               StringValue opzArg =(StringValue)arguments[1].getFormulaValue();
        
             String dataString = dataStringArg.getString();
             String opz=opzArg.getString();
        
        
        
        
        
            String returnVal = doTranslation(dataString,opz);
        
            return StringValue.fromString(returnVal);
           }
        
           @Override
           public final FormulaFunctionArgumentDefinition[] getArguments()
          {
             return this.myArguments;
          }
        
         @Override  
        public final FormulaValueType getReturnType()
          {
             return FormulaValueType.string;
           }
        
        
           protected abstract String translate(String inputData,String opz)
           throws InvalidBarcodeDataException;
        
        //protected abstract String translate(String inputData)
        //throws InvalidBarcodeDataException;
        
         // private String translateCharWrapper(String inputData)
           private String translateCharWrapper(String inputData,String opz)
          {
             String returnString;
        
             try
            {
                // returnString = translate(inputData);
              returnString = translate(inputData,opz);
             } catch (InvalidBarcodeDataException e) {
              returnString = "";
             }
        
            return returnString;
          }
        
        
        
           @Override
           public void validateArgumentValues(FormulaValueReference[] arguments)
             throws FormulaFunctionCallException
           {}
         }
        
        public class CodeEAN13
          extends CodeEAN13Base
        {
        
            //protected String opz;
        
        
        
           @Override
           public String getIdentifier()
           {
            return "barcodeean13";
          }
        
        
        
          private static String oddBar(String code) {
        
                return String.valueOf((char)(65+Integer.parseInt(code)));
        
            }
        
          private static String evenBar(String code) {
        
                return String.valueOf((char)(75+Integer.parseInt(code)));
        
            }
        
        
        @Override
        
            protected String translate(String inputData, String opz) throws InvalidBarcodeDataException {   
        
             Integer checkDigitSubtotal;
             String checkDigit;
              String temp = null;
              String code=inputData;
              String azalea_EAN13 = null;
              String opzM=opz;
        
        
        //    if(!opzM.equals(null)) {
        //     code=code+opzM;
        //    }
        
              //Calculate the EAN-13 check digit.
        
              checkDigitSubtotal=3*(Integer.parseInt(code.substring(1, 2))+Integer.parseInt(code.substring(3, 4))+Integer.parseInt(code.substring(5, 6))
                                   +Integer.parseInt(code.substring(7, 8))+Integer.parseInt(code.substring(9, 10))
                                   +Integer.parseInt(code.substring(code.length()-1)));
        
        
              checkDigitSubtotal=checkDigitSubtotal+(Integer.parseInt(code.substring(0,1))+Integer.parseInt(code.substring(2, 3))
                                               +Integer.parseInt(code.substring(4, 5))+Integer.parseInt(code.substring(6, 7))
                                               +Integer.parseInt(code.substring(8, 9))+Integer.parseInt(code.substring(10, 11)));
        
          checkDigit=String.valueOf(300-checkDigitSubtotal);
          checkDigit=checkDigit.substring(checkDigit.length()-1);
        
        
        
         // Begin building the output string with the 1st character's human-readable, L guard bars & odd parity of 1st digit
           temp=(char)(194+Integer.parseInt(code.substring(0,1)))+"x"+oddBar(code.substring(1, 2));  
        
          // Build the remainder of left half of symbol's parity is based on 1st digit
           switch (code.substring(0,1)) {
           case "0":
              {
                 //temp="U|x"; 
                 temp=temp+oddBar(code.substring(2, 3));
                 temp=temp+oddBar(code.substring(3, 4));
                 temp=temp+oddBar(code.substring(4, 5));
                 temp=temp+oddBar(code.substring(5, 6));
                 temp=temp+oddBar(code.substring(6, 7));         
              }
            break;
           case "1":
              {
                  //temp="[|x";
                  temp=temp+oddBar(code.substring(2, 3)); 
                  temp=temp+evenBar(code.substring(3, 4));
                  temp=temp+oddBar(code.substring(4, 5));
                  temp=temp+evenBar(code.substring(5, 6));
                  temp=temp+evenBar(code.substring(6, 7));
              }
              break;
           case "2":
           {
               //temp="V|x";
               temp=temp+oddBar(code.substring(2, 3));
               temp=temp+evenBar(code.substring(3, 4));
               temp=temp+evenBar(code.substring(4, 5));
               temp=temp+oddBar(code.substring(5, 6));
               temp=temp+evenBar(code.substring(6, 7));
           }
           break;
           case "3":
           {
               //temp="W|x";
               temp=temp+oddBar(code.substring(2, 3));
               temp=temp+evenBar(code.substring(3, 4));
               temp=temp+evenBar(code.substring(4, 5));
               temp=temp+evenBar(code.substring(5, 6));
               temp=temp+oddBar(code.substring(6, 7));
           }
            break;
           case "4":
           {
               //temp="X|x";
               temp=temp+evenBar(code.substring(2, 3));
               temp=temp+oddBar(code.substring(3, 4));
               temp=temp+oddBar(code.substring(4, 5));
               temp=temp+evenBar(code.substring(5, 6));
               temp=temp+evenBar(code.substring(6, 7));
        
           }
           break;
           case "5":
           {
               //temp="Y|x";
               temp=temp+evenBar(code.substring(2, 3));
               temp=temp+evenBar(code.substring(3, 4));
               temp=temp+oddBar(code.substring(4, 5));
               temp=temp+oddBar(code.substring(5, 6));
               temp=temp+evenBar(code.substring(6, 7));
        
           }
           break;
           case "6":
           {
               //temp="Z|x";
               temp=temp+evenBar(code.substring(2, 3));
               temp=temp+evenBar(code.substring(3, 4));
               temp=temp+evenBar(code.substring(4, 5));
               temp=temp+oddBar(code.substring(5, 6));
               temp=temp+oddBar(code.substring(6, 7));
        
           }
           break;
           case "7":
           {
               //temp="u|x";
               temp=temp+evenBar(code.substring(2, 3));
               temp=temp+oddBar(code.substring(3, 4));
               temp=temp+evenBar(code.substring(4, 5));
               temp=temp+oddBar(code.substring(5, 6));
               temp=temp+evenBar(code.substring(6, 7));
        
        
        
           }
           break;
           case "8":
           {
               //temp="\\|x";
               temp=temp+evenBar(code.substring(2, 3));
               temp=temp+oddBar(code.substring(3, 4));
               temp=temp+evenBar(code.substring(4, 5));
               temp=temp+evenBar(code.substring(5, 6));
               temp=temp+oddBar(code.substring(6, 7));
        
           }
           break;
           case "9":
           {
               //temp="]|x";
               temp=temp+evenBar(code.substring(2, 3));
               temp=temp+evenBar(code.substring(3, 4));
               temp=temp+oddBar(code.substring(4, 5));
               temp=temp+evenBar(code.substring(5, 6));
               temp=temp+oddBar(code.substring(6, 7));
        
           }
           break;
        
            default:
           }
        
        ////Add the center guard bars & the build right half of symbol using set C (0-9)
        
        
            return azalea_EAN13+opzM;
           }
        
        
        
        
         }
        
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-05-11
          • 2011-12-12
          • 2014-09-05
          • 1970-01-01
          • 2016-03-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多