我之前使用过BigDecimals但不经常使用BigDecimals,今天早上我正在处理一些事情并且我一直遇到以下异常:
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion;
no exact representable decimal result.
at java.math.BigDecimal.divide(BigDecimal.java:1594)
Run Code Online (Sandbox Code Playgroud)
我试图设置比例并使用舍入来消除这样的问题:
BigDecimal bd1 = new BigDecimal(1131).setScale(2,BigDecimal.ROUND_HALF_UP);
BigDecimal bd2 = new BigDecimal(365).setScale(2,BigDecimal.ROUND_HALF_UP);
BigDecimal bd3 = bd1.divide(bd2).setScale(2,BigDecimal.ROUND_HALF_UP);
System.out.println("result: " + bd3);
Run Code Online (Sandbox Code Playgroud)
但是,我一直得到同样的例外.有谁能告诉我我犯了哪个错误?
什么时候才能最好地利用这种类型的例外,如果陷入这种类型的捕获,它是否正确处理?
catch(Exception e)
Run Code Online (Sandbox Code Playgroud)
还是需要明确捕获?
catch(IllegalArgumentException e)
Run Code Online (Sandbox Code Playgroud) 我已经有很长一段时间没有做过任何C++编程了,我决定在业余时间把它搞砸一下,所以我决定给我写一个小数据库程序只是为了好玩,我在创建时遇到了麻烦一组模板化的类对象.
我所拥有的是这个类,我想用它来表示数据库记录中的字段.
template <class T, int fieldTypeId>
class Field
{
private:
T field;
int field_type;
public:
// ...
};
Run Code Online (Sandbox Code Playgroud)
我想使用该类的数组来表示使用此类的数据库中的记录.
class Database_Record
{
private:
int id;
Field record[];
public:
Database_Record(int);
Database_Record(int, Field[]);
~Database_Record();
};
Run Code Online (Sandbox Code Playgroud)
我坚持的地方是在类中创建数组,Database_Record
因为这是一个模板化类对象的数组,每个元素可能是不同的类型,我不知道我是否需要声明数组因此.我正在努力做甚至可能,还是我错误的方式?任何帮助将不胜感激.
我最近一直在研究符合ACORD P&C的Web服务,并且遇到了一些麻烦,因为wsimport错误地说它无法解析其中一个xsd文件.错误消息是:
[ERROR] Unable to parse "D:\projects\DICACORD\DicAcordQuoteRq.xsd" : Illegal character in opaque part at index 2: D:\projects\DICACORD\DicAcordQuoteRq.xsd
Run Code Online (Sandbox Code Playgroud)
我创建的模式基于ACORD P&C模式(超过23k行),我只包含了公司需要使用的必需元素.我使用XMLSpy创建了模式,根据其验证,模式是有效的,但是当我尝试在netbeans 6.8中创建Web服务时,我收到上面的错误消息.
模式在我的开发机器上,根据我在netbeans论坛上可以找到的内容,netbeans将wsdl复制到项目内部的一个目录中,这样当你将它从开发转移到生产时,一切都仍然像它应该的那样工作.
wsdl如下
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2010 -->
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="discoveryinsurance.com/schemas" xmlns:ns="discoveryinsurance.com/schemas/acordRq" xmlns:ns1="discoveryinsurance.com/schemas/acordRs" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="discoveryinsurance.com/schemas">
<wsdl:import namespace="discoveryinsurance.com/schemas/acordRq" location="D:\projects\DICACORD\DicAcordQuoteRq.xsd"/>
<wsdl:import namespace="discoveryinsurance.com/schemas/acordRs" location="D:\projects\DICACORD\DicAcordQuoteRs.xsd"/>
<wsdl:types>
<xs:schema targetNamespace="discoveryinsurance.com/schemas" elementFormDefault="qualified"/>
</wsdl:types>
<wsdl:message name="NewMessageRequest">
<wsdl:part name="parameter" element="ns:ACORD"/>
</wsdl:message>
<wsdl:message name="NewMessageResponse">
<wsdl:part name="parameter" element="ns1:ACORD"/>
</wsdl:message>
<wsdl:portType name="QuotePort">
<wsdl:operation name="QuoteRequest">
<wsdl:input name="quoteInput" message="tns:NewMessageRequest"/>
<wsdl:output name="quoteOutput" message="tns:NewMessageResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding …
Run Code Online (Sandbox Code Playgroud) 我遇到的问题是,当我尝试使用这个wsdl在netbeans中创建一个Web服务时,netbeans说没有定义服务.我是整个wsdl的新手,但据我所知,有一个定义.
wsdl是:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://discoveryinsurance.com/DicQuoteSvc/AgencyQuote.wsdl" xmlns:ns="http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRq.xsd" xmlns:na="http://discoveryinsurance.com/DicQuoteSvc/schemas/DicAcordQuoteRs.xsd" targetNamespace="http://discoveryinsurance.com/DicQuoteSvc/AgencyQuote.wsdl">
<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" location="DicAcordQuoteRq.xsd"/>
<wsdl:import namespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" location="DicAcordQuoteRs.xsd"/>
<wsdl:types>
<xs:schema targetNamespace="http://discoveryinsurance.com/DicQuoteSvc/schemas/" elementFormDefault="qualified"/>
</wsdl:types>
<wsdl:message name="NewMessageRequest">
<wsdl:part name="parameter" element="ns:ACORD"/>
</wsdl:message>
<wsdl:message name="NewMessageResponse">
<wsdl:part name="parameter" element="na:ACORD"/>
</wsdl:message>
<wsdl:portType name="QuotePortType">
<wsdl:operation name="RequestQuote">
<wsdl:input message="tns:NewMessageRequest"/>
<wsdl:output message="tns:NewMessageResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="QuoteBinding" type="tns:QuotePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="RequestQuote">
<soap:operation soapAction="http://discoveryinsurance.com/DicQuoteSvc/AgencyQuote" style="rpc"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AgencyQuote">
<wsdl:port name="QuotePortType" binding="tns:QuoteBinding">
<soap:address location="http://discoveryinsurance.com/DicQuoteSvc/"/>
</wsdl:port>
</wsdl:service> …
Run Code Online (Sandbox Code Playgroud) java ×4
exception ×2
netbeans6.8 ×2
web-services ×2
wsdl ×2
arrays ×1
bigdecimal ×1
c++ ×1
templates ×1