English 中文(简体)
在试图使用java.lang时,找不到“形式方法”。 A. 低温反应模式方法
原标题:Getting "The format method was not found" when trying to use java.lang.string format method from ColdFusion

I want to do something in ColdFusion that is similar to sprintf in C or Perl. I found this answer, which seems to be what I m looking for. However, I can t get it to work.

我在此试图:

<cftry>
    <cfset firstName="John">
    <cfset output=createObject("java","java.lang.String").format("Hello, %s!", firstName)>
    <cfcatch type="any">
        <cfdump var="#cfcatch#" expand="false">
    </cfcatch>
<cftry>

这里我得到的是:

副渔获物。 电文:没有找到格式方法。

cfcatch.Detail: Either there are no methods with the specified method name and argument types or the format method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

这是一个超负荷的方法,因此,我按照建议使用 JavaCast的论点:

<cfset output=createObject("java","java.lang.String").format(JavaCast( string , "Hello, %s!"), firstName)>
<cfset output=createObject("java","java.lang.String").format("Hello, %s!", JavaCast( string , firstName))>
<cfset output=createObject("java","java.lang.String").format(JavaCast( string , "Hello, %s!"), JavaCast( string , firstName))>

并且每次都出现同样的错误。

我在Sting阶级、价值Of上尝试了另一种静态方法,并做了罚款。

Edit: I ve already seen a comment, and I m not sure how to respond to those, but maybe I should explain here. What I ve shown above is an extremely simplified example of what I am trying to do. The goal is to use a format string to provide lots of formatting in one place, and then simply pass in a list of variables, instead of formatting a bunch of variables and outputting them, or formatting them as I m outputting them. With the format method, I plan to build a set of format strings that match the output I need, then I will just cfloop or cfoutput over a query, run this one method inside, and get the output I want. No DateFormat, NumberFormat, Left, Right, etc. If I can t get this working, that is plan B though.

I m 驾 Cold9.01,Windows 7, Java 1.6.0_22。

非常赞赏一切帮助。

最佳回答

Answer based on my comment above:

它可能与你重新寻找的形式相匹配,因为它的签字是格式(编码、目标),而你的第二大论点可能不会自动转化为目标阵列。

您可以改变这一论点,将名称归入如下阵列:format('Hello, %>,[firstName]

Thanks to 说得如此仓促,我发表以下评论:

问题回答

暂无回答




相关问题
JQuery AJAX .load - flash chart doesnt load in IE

An IE issue has me completely stumped. I have a coldfusion page that uses JQuery s AJAX .load function to load in a new flash file that is generated by coldFusion s cfchart tag. This works completely ...

Best Coldfusion Library for OpenID [closed]

I am getting ready to start a project that requires using OpenID within Coldfusion 8. I have found a number of different options and was wondering what has worked the best, get s the most support, ...

Find ColdFusion Generated ID

Is there a way to find the elements generated by ColdFusion s <CFLayout> and <CFLayoutArea> tags? These tags: <cflayout type="tab" name="MyAccount"> <cflayoutarea name="...

ColdFusion COM error

I am upgrading from CF4.5 to CF8. Calls to COM dll s that used to work in version 4.5 now throw a "Complex object types cannot be converted to simple values.." error. The COM object has a few arrays ...

What s the best way to write engine-specific CFML code?

Sometimes it is necessary to write different code for Adobe ColdFusion vs Railo vs OpenBD, due to differences in implementation. Do people have a specific method that they use for this? For example, ...

热门标签