Not able to trace the crash because of inconsistency - c++

I am making a blackjack game in cocos2d-x here is the following code of the same where I am getting crash but can not understant why this is happening whats going wrong ? I tried several things thinking that crash might be because of string memory leak or something
CCSprite* _big = CCSprite::createWithSpriteFrameName(ptr);
Here is the card cpp file which inherits CCSprite
Card.cpp
#include "Card.h"
Card::Card() {
}
Card::~Card() {
}
void Card::init(int value, int suit) {
mValue = value;
mSuit = suit;
mGameValue = 0;
UnHide();
}
void Card::UnHide() {
mHidden = false;
//if(this)
//this->removeAllChildrenWithCleanup(true);
//this->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("card"));
this->initWithSpriteFrameName("card");
char strName[64]={0};
//memset ( strName, 0, sizeof ( strName ));
switch(mSuit){
case 0: sprintf(strName,"%s","club_big");break;
case 1: sprintf(strName,"%s","diamond_big");break;
case 2: sprintf(strName,"%s","spade_big");break;
case 3: sprintf(strName,"%s","heart_big");break;
default :
break;
}
const char *ptr = strdup(strName);
CCSprite* _big = CCSprite::createWithSpriteFrameName(ptr);
delete ptr;
// CCSprite* big = CCSprite::create(strName);
_big->setPosition(ccp(55, 44));
this->addChild(_big);
switch(mSuit){
case 0: sprintf(strName,"%s","club");break;
case 1: sprintf(strName,"%s","diamond");break;
case 2: sprintf(strName,"%s","spade");break;
case 3: sprintf(strName,"%s","heart");break;
default :
break;
}
const char *_ptr = strdup(strName);
CCSprite* _small = CCSprite::createWithSpriteFrameName(_ptr);
delete _ptr;
// CCSprite* small = CCSprite::create(str);
_small->setPosition(ccp(16, 82));
this->addChild(_small);
if(mSuit==0 || mSuit==2){
switch(mValue){
case 1: sprintf(strName,"%s","blacka");mGameValue = 1;break;
case 2: sprintf(strName,"%s","black2");mGameValue = mValue;break;
case 3: sprintf(strName,"%s","black3");mGameValue = mValue;break;
case 4: sprintf(strName,"%s","black4");mGameValue = mValue;break;
case 5: sprintf(strName,"%s","black5");mGameValue = mValue;break;
case 6: sprintf(strName,"%s","black6");mGameValue = mValue;break;
case 7: sprintf(strName,"%s","black7");mGameValue = mValue;break;
case 8: sprintf(strName,"%s","black8");mGameValue = mValue;break;
case 9: sprintf(strName,"%s","black9");mGameValue = mValue;break;
case 10: sprintf(strName,"%s","black10");mGameValue = mValue;break;
case 11: sprintf(strName,"%s","blackj");mGameValue = 10;break;
case 12: sprintf(strName,"%s","blackq");mGameValue = 10;break;
case 13: sprintf(strName,"%s","blackk");mGameValue = 10;break;
default :
break;
}
}
else {
switch(mValue){
case 1: sprintf(strName,"%s","reda");mGameValue = 1;break;
case 2: sprintf(strName,"%s","red2");mGameValue = mValue;break;
case 3: sprintf(strName,"%s","red3");mGameValue = mValue;break;
case 4: sprintf(strName,"%s","red4");mGameValue = mValue;break;
case 5: sprintf(strName,"%s","red5");mGameValue = mValue;break;
case 6: sprintf(strName,"%s","red6");mGameValue = mValue;break;
case 7: sprintf(strName,"%s","red7");mGameValue = mValue;break;
case 8: sprintf(strName,"%s","red8");mGameValue = mValue;break;
case 9: sprintf(strName,"%s","red9");mGameValue = mValue;break;
case 10: sprintf(strName,"%s","red10");mGameValue = mValue;break;
case 11: sprintf(strName,"%s","redj");mGameValue = 10;break;
case 12: sprintf(strName,"%s","redq");mGameValue = 10;break;
case 13: sprintf(strName,"%s","redk");mGameValue = 10;break;
default :
break;
}
}
const char *_ptrr = strdup(strName);
CCSprite* _num = CCSprite::createWithSpriteFrameName(_ptrr);
delete _ptrr;
// CCSprite* _num = CCSprite::create(strName);
_num->setPosition(ccp(18, 108));
this->addChild(_num);
}
void Card::Hide() {
mHidden = true;
this->removeAllChildrenWithCleanup(true);
this->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("deck"));
//this->initWithSpriteFrameName("deck");
}
Intialization of cards is as per this
for (int suit = 0; suit < 4; suit++) {
for (int value = 0; value < 13; value++) {
Card* card = new Card;
//card->init
card->init(value+1, suit);
mCard[suit*13 + value] = card;
}
}
The crash I get is on the line of initWithSpriteFrameName but it doesnt occur frequently

h file:
class Card : public cocos2d::Node
{
public:
int mValue;
int mSuit;
bool mHidden;
int mGameValue;
CCSprite* front;
CCSprite* back;
static Card* create();
bool init(int value, int suit);
void UnHide();
void Hide();
};
cpp file
Card* Card::create(int value, int suit){
Card* card = new Card();
if(card && card->init(value, suit)){
card->autorelease();
return card;
}
else{
CC_SAFE_DELETE(card);
return NULL;
}
}
bool Card::init(int value, int suit) {
if(CCNode::init()){
mValue = value;
mSuit = suit;
mGameValue = 0;
//create your front and back sprite here as what you did in Unhide
CCSprite* back = blablabla;
CCSprite* front = blablabla;
//add them as a child of current node
this->addChild(back);
this->addChild(front);
this->UnHide();
return true;
}
return false;
}
void Card::UnHide() {
back->setVisible(false);
front->setVisible(true);
}
void Card::Hide() {
back->setVisible(true);
front->setVisible(false);
}
and for your deck, from my understanding,
CCArray::createWithCapacity(52);
will be a better choice.

Related

The C++ Programming Language 4th edition A desk calculator return ct={Kind::name;} the output is wrong when i input pi

when i copy the code from the book The C++ Programming Language Fourth Edition ,Bjarne Stroustrup
I found out that when i input a pi(which has been defined in the code) the output is wrong
so i spent 1 day to find out the problem. i just share it
#include<iostream>
#include<map>
#include<string>
#include<sstream>
#include<cctype>
enum class Kind:char{
name,number,end,
plus='+',minus='-',mul='*',div='/',print=';',assign='=',lp='(',rp=')'
};
struct Token{
Kind kind;
std::string string_value;
double number_value;
};
int no_of_errors;
double error(const std::string& s)
{
no_of_errors++;
std::cerr<<"error: "<<s<<'\n';
return 1;
}
std::map<std::string,double> table;
double expr(bool get);
double term(bool get);
double prim(bool get);
class Token_stream{
public:
Token_stream(std::istream& s):ip{&s},owns{false}{}
Token_stream(std::istream* p):ip{p},owns{true}{}
~Token_stream(){close();}
Token get();
Token& current(){return ct;}
void set_input(std::istream& s){close();ip=&s;owns=false;}
void set_input(std::istream* p){close();ip=p;owns=true;}
private:
void close(){if(owns) delete ip;}
std::istream* ip;
bool owns;
Token ct{Kind::end};
};
Token_stream ts{std::cin};
//Token& Token_stream::current()
//{
// return ct;
//}
Token Token_stream::get()
{
char ch;
do{
if(!ip->get(ch)){
return ct={Kind::end};
}
}while(ch!='\n' && std::isspace(ch));
switch(ch){
case ';':
case '\n':
return ct={Kind::print};
case '*':
case '/':
case '+':
case '-':
case '(':
case ')':
case '=':
return ct={static_cast<Kind>(ch)};
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':{
ip->putback(ch);
*ip>>ct.number_value;
ct.kind=Kind::number;
return ct;
}
default:
if(std::isalpha(ch)){
ct.string_value = ch;
while(ip->get(ch) && std::isalnum(ch)){
ct.string_value +=ch;
}
//test
//std::cout<<ts.current().string_value<<'\n';
//std::cout<<table[ct.string_value]<<'\n';
ip->putback(ch);
return ct={Kind::name,ct.string_value};
}
error("bad token");
return ct={Kind::print};
}
}
double expr(bool get)
{
//test
// std::cout<<ts.current().string_value<<'\n';
// std::cout<<table[ts.current().string_value]<<'\n';
double left=term(get);
for(;;){
switch(ts.current().kind){
case Kind::plus:
left += term(true);
break;
case Kind::minus:
left-= term(true);
break;
default:
return left;
}
}
}
double term(bool get)
{
double left = prim(get);
for(;;){
switch(ts.current().kind){
case Kind::mul:
left *= prim(true);
break;
case Kind::div:
if(auto d = prim(true)){
left /= d;
break;
}
return error("divide by 0");
default:
return left;
}
}
}
double prim(bool get)
{
if(get){
ts.get();
}
switch(ts.current().kind){
case Kind::number:
{
double v=ts.current().number_value;
ts.get();
return v;
}
case Kind::name:
{
//test
//std::cout<<ts.current().string_value<<'\n';
double& v=table[ts.current().string_value];
//std::cout<<table[ts.current().string_value]<<'\n';
if(ts.get().kind == Kind::assign){
v=expr(true);
}
//std::cout<<ts.current().string_value<<'\n';
//std::cout<<v<<'\n';
//std::cout<<table[ts.current().string_value]<<'\n';
return v;
}
case Kind::lp:
{
auto e = expr(true);
if(ts.current().kind!=Kind::rp){
return error("')' expected");
}
void(ts.get());
return e;
}
default:
return error("primary expected");
}
}
void calculate()
{
for(;;){
ts.get();
//test
//if(ts.current().kind != Kind::number){
// std::cout<<"number"<<'\n';
//}
if(ts.current().kind == Kind::end)break;
if(ts.current().kind == Kind::print)continue;
std::cout<<expr(false)<<'\n';
}
}
int main(int arg,char* argv[])
{
switch(arg){
case 1:
break;
case 2:
ts.set_input(new std::istringstream{argv[1]});
break;
default:
error("too many arguments");
return 1;
}
table["pi"] = 3.1415926535897932385;
table["e"] = 2.7182818284590452354;
calculate();
return no_of_errors;
}
233,1 Bot
the most important for correct the error is as follows:
//in member function Token Token_stream::get()
//old code:
return ct={Kind::name;}
we should change the code like this:
//in member function Token Token_stream::get()
//new code:
return ct={Kind::name,ct.string_value}

Parsing a file to assign variables to strucuture. C++

Here is my code, I'm genuinely interested how far off I am.
bool characterGetCFG(char typeOverLoad, string var_name, string full_text)
{
int pos = full_text.find(var_name) + 1;
if (full_text.at(pos) == *"t") {
cout << "returned " << full_text.at(pos) << "\n";
return true;
}
else
{
return false;
}
}
int characterGetCFG(int typeOverLoad, string var_name, string full_text)
{
int pos = full_text.find(var_name) + var_name.length() + 1;
cout << "returned " << full_text.at(pos) << "\n";
return full_text.at(pos);
}
features setconfig(features featstruct)
{
features config; //BOOL/BOOL/BOOL/BOOL/INT[2]/BOOL/INT
ifstream file;
file.open("config.cfg");
if (!file.is_open()) {
exit(-1);
}
string raw;
while (file.good()) {
file >> raw;
}
for (int x = 0; x < 11; x++) {
switch (x) {
case 1:
config.var1 = characterGetCFG('t', "var1", raw);
case 2:
config.var2 = characterGetCFG('t', "var2", raw);
case 3:
config.var3 = characterGetCFG('t', "var3", raw);
case 4:
config.var4 = characterGetCFG('t', "var4", raw);
case 5:
config.var5[1] = characterGetCFG(136, "var51", raw); //min
case 6:
config.var6[2] = characterGetCFG(542, "var62", raw); //max
case 7:
config.var7 = characterGetCFG('t', "var7", raw);
case 8:
config.var8 = characterGetCFG('t', "var8", raw);
case 9:
config.var9 = characterGetCFG('t', "var9", raw);
case 10:
config.var10 = characterGetCFG('t', "var10", raw);
case 11:
config.var11 = characterGetCFG('t', "var11", raw);
}
}
file.close();
return config;
}
And here is my text/cfg file I am using
var1=false
var2=false
var3=true
var4=false
var51=2
var62=7
var7=true
var8=t
var9=true
var10=true
var11=true
Here is what I am getting returned when I print what I am returning to console
As you can see it does not reflect how many times I iterate through the loop, so at the end of the day I'm stumped.

Why does my check not work in checking for duplicated results( pointers)

int main()
{ srand(time(NULL));
Card c;
Card *Pc;
Pc = new Card [52];
Card ** someHands;
// typedef Card * Hand;
// Hand *someHands;
CardtoArray(c,Pc);
printDeckofCards(Pc,c);
}
Card GenerateCards(Card c)
{
int CardNum;
CardNum=rand() % 13 + 1;
int colour =rand() % 4 + 1;
switch(CardNum)
{
case 1: c.rank= Ace;
break;
case 2: c.rank= Two;
break;
case 3: c.rank= Three;
break;
case 4: c.rank= Four;
break;
case 5: c.rank= Five;
break;
case 6: c.rank= Six;
break;
case 7: c.rank= Seven;
break;
case 8: c.rank= Eight;
break;
case 9: c.rank= Nine;
break;
case 10: c.rank= Ten;
break;
case 11: c.rank= Jack;
break;
case 12: c.rank= Queen;
break;
case 13: c.rank= King;
break;
}
switch(colour)
{
case 1:c.color="Diamond";
break;
case 2:c.color="Club";
break;
case 3:c.color="Heart";
break;
case 4:c.color="Spade";
break;
}
return c;
}
//prints a single card this function is to be call into the function //printsdeckofcards
void printCard(Card c)
{
cout<<*c.color;
if(c.rank==Ace)
cout<<"A";
else if(c.rank==Two)
cout<<"2";
else if(c.rank==Three)
cout<<"3";
else if(c.rank==Four)
cout<<"4";
else if(c.rank==Five)
cout<<"5";
else if(c.rank==Six)
cout<<"6";
else if(c.rank==Seven)
cout<<"7";
else if(c.rank==Eight)
cout<<"8";
else if(c.rank==Nine)
cout<<"9";
else if(c.rank==Ten)
cout<<"10";
else if(c.rank==Jack)
cout<<"J";
else if(c.rank==Queen)
cout<<"Q";
else if(c.rank==King)
cout<<"K";
}
//generate and inserts 52 cards it also calls the function samecard to check if
//duplicated cards have been generated and if so regenerates a new one before //inserting into the array
void CardtoArray(Card &c,Card *Pc)
{
Card *origin;
origin=Pc;
for( int i=0;i<52;i++)
{
c=GenerateCards(c);
if(SameCard(c,origin)==false)
{
*Pc=c;
Pc++;
}
else
i--;
}
}
void printDeckofCards(Card *Pc,Card c)
{
for( int i=0;i<52;i++)
{
printCard(*Pc);
cout<<" ";
Pc++;
}
}
bool SameCard(Card c,Card *Pc)
{ bool check;
for(int i=0; i<52; i++)
{
if(Pc->color==c.color && Pc->rank==c.rank)
{
check = true;
}
else
{
check = false;
}
Pc++;
}
return check;
}
Blockquote
Because you are checking ALL cards, your boolean must be set to false before the loop and is set to true in the loop; it should not be set to false again in the loop:
bool SameCard(Card c,Card *Pc)
{ bool check= false;
for(int i=0; i<52; i++)
{
if(Pc->color==c.color && Pc->rank==c.rank)
{
check = true;
}
//else
///{
// check = false;
//}
Pc++;
}
return check;
}
or even:
bool SameCard(Card c,Card *Pc)
{
for(int i=0; i<52; i++, pc++)
if(Pc->color==c.color && Pc->rank==c.rank)
return true;
return false;
}

Switch statement will NOT print a string

char gamerCentral::getGamerTag( )
{
switch(gamerTag)
{
case '1': return gamerTag = "Diamond";
break;
case '2': return gamerTag = "Silver";
break;
case '3': return gamerTag = "Bronze";
break;
case '4': return gamerTag = "Wood";
break;
default: return gamerTag = "Uninstall";
break;
}
char gamerTag;
GamerClub::GamerClub(
char tag)
{
gamerTag = tag;
}
I'm trying to return the gamerTag, but it says that it cannot convert to a string. Is their a way to convert the char to a string inside the switch statement?
Have your function return a string, it can still operate on the single character as input. Here's an example.
std::string getGamerTag(char t)
{
switch(t)
{
case '1': return "Diamond";
case '2': return "Silver";
// ...
}
return "";
}
// prints "Silver"
cout << getGamerTag('2');
use string variable or use char*
char* getGamerTag(int t)
{
switch(t)
{
case 1: return "Diamond";
case 2: return "Silver";
}
}
int main()
{
cout << getGamerTag(2);
}
I recommend using an array of strings:
std::string getGamerTag(unsigned int t)
{
static const char * tag_names[] =
{
"Diamond", "Silver", "Bronze", "Wood", "Unistall",
};
static const unsigned int name_quantity =
sizeof(tag_names) / sizeof(tag_names[0]);
std::string name;
if ((t > 0) && (t <= name_quantity))
{
name = tag_names[t - 1];
}
return name;
}

KSOAP2 can send complex type but can't receive it back

I'm working on a project that needs to access a 3rd party dotNet WebService.
I'm using ksoap2-j2se-full-2.1.2.jar (Java 1.4 compatible).
I can't use java > 1.4 (platform restrictions).
It uses a lot of complex data types.
There is a particular method that receives a complex object and returns the same object type (possibly modified).
The serialization works ok, but the deserialization is not working.
The "atributos" tag is causing the error.
Does anyone know whether it is possible to use the same registered data type for both ways or at least a better way than doying that by hand (I'll have to do for a lot of methods)?
Sorry for the long long long message. But I had to include everything related to that.
Sorry for the sloppy code. This is just a test.
Thanks very much.
Here is the request XML:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header/>
<v:Body>
<iniciarExecucaoProcessoComTicket xmlns="http://tempuri.org/" id="o0" c:root="1">
<ticketAutenticacao>4FSejSSb5JY8N5Sy+nwYDOxNaBsPhFuyF9Dsws8AiNQvwN0nGOUP8w==</ticketAutenticacao>
<idProcesso>10074</idProcesso>
<parametrosIniciais>
<n0:KeyValue xmlns:n0="http://schemas.datacontract.org/2004/07/MyWS.WS.EXT">
<n0:key>pnNome</n0:key>
<n0:value i:type="d:string">Person1</n0:value>
</n0:KeyValue>
<n1:KeyValue xmlns:n1="http://schemas.datacontract.org/2004/07/MyWS.WS.EXT">
<n1:key>pnNumero</n1:key>
<n1:value i:type="d:string">7001832700</n1:value>
</n1:KeyValue>
<n2:KeyValue xmlns:n2="http://schemas.datacontract.org/2004/07/MyWS.WS.EXT">
<n2:key>pnTipoSAP</n2:key>
<n2:value i:type="d:string">Z005</n2:value>
</n2:KeyValue>
<n3:KeyValue xmlns:n3="http://schemas.datacontract.org/2004/07/MyWS.WS.EXT">
<n3:key>CodCanal</n3:key>
<n3:value i:type="d:string">5</n3:value>
</n3:KeyValue>
</parametrosIniciais>
</iniciarExecucaoProcessoComTicket>
</v:Body>
</v:Envelope>
Here is the answer XML:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<iniciarExecucaoProcessoComTicketResponse xmlns="http://tempuri.org/">
<iniciarExecucaoProcessoComTicketResult xmlns:a="http://schemas.datacontract.org/2004/07/MyWS.WS.EXT" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:atributos>
<a:KeyValue>
<a:key>pnNome</a:key>
<a:value xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">Person 1</a:value>
</a:KeyValue>
<a:KeyValue>
<a:key>pnNumero</a:key>
<a:value xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">7001832700</a:value>
</a:KeyValue>
<a:KeyValue>
<a:key>pnTipoSAP</a:key>
<a:value xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">Z005</a:value>
</a:KeyValue>
<a:KeyValue>
<a:key>CodCanal</a:key>
<a:value xmlns:b="http://www.w3.org/2001/XMLSchema" i:type="b:string">5</a:value>
</a:KeyValue>
</a:atributos>
<a:dominio>0</a:dominio>
<a:ds xmlns:b="http://schemas.datacontract.org/2004/07/MyWS.DTO" i:nil="true"/>
<a:idInstanciaProcesso>66806</a:idInstanciaProcesso>
<a:idProcesso>10074</a:idProcesso>
<a:instanciaEmExecucao xmlns:b="http://schemas.datacontract.org/2004/07/MyWS.DTO" i:nil="true"/>
<a:nomeUsuario>7001832700</a:nomeUsuario>
<a:revisao>15076</a:revisao>
<a:statusInstanciaProcesso>NaoIniciado</a:statusInstanciaProcesso>
</iniciarExecucaoProcessoComTicketResult>
</iniciarExecucaoProcessoComTicketResponse>
</s:Body>
</s:Envelope>
Here is the exception:
Unknown Property: KeyValue
java.lang.RuntimeException: Unknown Property: KeyValue
at org.ksoap2.serialization.SoapSerializationEnvelope.readSerializable(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.read(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.readSerializable(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.read(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.readSerializable(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.read(Unknown Source)
at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(Unknown Source)
at org.ksoap2.SoapEnvelope.parse(Unknown Source)
at org.ksoap2.transport.Transport.parseResponse(Unknown Source)
at org.ksoap2.transport.HttpTransportSE.call(Unknown Source)
at ServicoSegundaVia.iniciarExecucaoProcessoComTicket(ServicoSegundaVia.java:194)
at ServicoSegundaVia.main(ServicoSegundaVia.java:25)
Exception in thread "main" java.lang.NullPointerException
at ServicoSegundaVia.main(ServicoSegundaVia.java:30)
Java Result: 1
Here is the code I'm using:
// Calling code
public static DadosInstanciaProcessoDTO iniciarExecucaoProcessoComTicket(){
//Get Ticket
String ticket = "XYZ"; // Got from somewhere else
//Conect on Service.......
String sNAMESPACE = "http://tempuri.org/";
String sMETHOD_NAME = "iniciarExecucaoProcessoComTicket";
String sURL = "http://192.168.0.197:88/WFPExecutorService.svc";
String sSOAPAACTION = "http://tempuri.org/IWFPExecutorService/iniciarExecucaoProcessoComTicket";
SoapObject request = new SoapObject(sNAMESPACE, sMETHOD_NAME);
request.addProperty("ticketAutenticacao", ticket);
request.addProperty("idProcesso", "10074");
ParametrosIniciais parIni = new ParametrosIniciais();
parIni.add(new KeyValue("pnNome", "Person 1"));
parIni.add(new KeyValue("pnNumero","7001832700"));
parIni.add(new KeyValue("pnTipoSAP","Z005"));
parIni.add(new KeyValue("CodCanal","5"));
PropertyInfo info = new PropertyInfo();
info.name = "parametrosIniciais";
info.type = ParametrosIniciais.class;
request.addProperty(info, parIni);
//ENVELOPE
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(sNAMESPACE, "iniciarExecucaoProcessoComTicketResponse", IniciarExecucaoProcessoComTicketResponse.class);
envelope.addMapping(sNAMESPACE, "iniciarExecucaoProcessoComTicketResult", DadosInstanciaProcessoDTO.class);
envelope.addMapping("http://schemas.datacontract.org/2004/07/MyWS.WS.EXT", "atributos", Atributos.class);
envelope.addMapping("http://schemas.datacontract.org/2004/07/MyWS.WS.EXT", "KeyValue", KeyValue.class);
//Creates a conection, using a String URL..
HttpTransportSE myHttpTransport = new HttpTransportSE(sURL);
myHttpTransport.debug = true;
try {
myHttpTransport.call(sSOAPAACTION, envelope);
IniciarExecucaoProcessoComTicketResponse response = (IniciarExecucaoProcessoComTicketResponse)envelope.bodyIn;
DadosInstanciaProcessoDTO dto = response.getDadosIniExecProc();
System.out.println(dto.getAtributo("pnNome"));
return dto;
} catch (Exception e) {
e.printStackTrace();
return null;
}
return null;
}
Data Types:
package data;
import java.util.Hashtable;
import java.util.Vector;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class Atributos extends Vector implements KvmSerializable {
public Object getProperty(int i) { return this.get(i); }
public int getPropertyCount() { return this.size(); }
public void setProperty(int i, Object o) { this.add(o); }
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo pi) {
pi.name = "KeyValue";
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
pi.type = KeyValue.class;
}
}
--
package data;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class DadosExecucaoDTO implements KvmSerializable {
private Atributos atributos = null;
private String sDominio = "";
private Object oDs = null;
private String sIdInstanciaProcesso = "";
private String sIdProcesso = "";
private Object oInstanciaEmExecucao = null;
private String sNomeUsuario = "";
private String sRevisao = "";
private String sStatusInstanciaProcesso = "";
public Object getProperty(int i) {
switch (i) {
case 0: return atributos;
case 1: return sDominio;
case 2: return oDs;
case 3: return sIdInstanciaProcesso;
case 4: return sIdProcesso;
case 5: return oInstanciaEmExecucao;
case 6: return sNomeUsuario;
case 7: return sRevisao;
case 8: return sStatusInstanciaProcesso;
}
return null;
}
public int getPropertyCount() {
return 9;
}
public void setProperty(int i, Object o) {
switch (i) {
case 0: this.atributos = (Atributos)o; break;
case 1: this.sDominio = o.toString(); break;
case 2: this.oDs = o; break;
case 3: this.sIdInstanciaProcesso = o.toString(); break;
case 4: this.sIdProcesso = o.toString(); break;
case 5: this.oInstanciaEmExecucao = o; break;
case 6: this.sNomeUsuario = o.toString(); break;
case 7: this.sRevisao = o.toString(); break;
case 8: this.sStatusInstanciaProcesso = o.toString(); break;
}
}
public void getPropertyInfo(int i, Hashtable hshtbl, PropertyInfo pi) {
switch (i) {
case 0:
pi.name = "atributos"; pi.type = Atributos.class;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
case 1:
pi.name = "dominio"; pi.type = PropertyInfo.STRING_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
case 2:
pi.name = "ds"; pi.type = PropertyInfo.OBJECT_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.DTO";
break;
case 3:
pi.name = "idInstanciaProcesso"; pi.type = PropertyInfo.STRING_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
case 4:
pi.name = "idProcesso"; pi.type = PropertyInfo.STRING_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
case 5:
pi.name = "instanciaEmExecucao"; pi.type = PropertyInfo.OBJECT_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.DTO";
break;
case 6:
pi.name = "nomeUsuario"; pi.type = PropertyInfo.STRING_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
case 7:
pi.name = "revisao"; pi.type = PropertyInfo.STRING_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
case 8:
pi.name = "statusInstanciaProcesso"; pi.type = PropertyInfo.STRING_CLASS;
pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
break;
}
}
}
--
package data;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class IniciarExecucaoProcessoComTicketResponse implements KvmSerializable {
private DadosInstanciaProcessoDTO iniciarExecucaoProcessoComTicketResult;
public DadosInstanciaProcessoDTO getDadosIniExecProc() {
return iniciarExecucaoProcessoComTicketResult;
}
public Object getProperty(int i) {
switch (i) {
case 0: return iniciarExecucaoProcessoComTicketResult;
}
return null;
}
public int getPropertyCount() {
return 1;
}
public void setProperty(int i, Object o) {
switch (i) {
case 0: this.iniciarExecucaoProcessoComTicketResult = (DadosInstanciaProcessoDTO)o; break;
}
}
public void getPropertyInfo(int index, Hashtable hshtbl, PropertyInfo info) {
switch (index) {
case 0:
info.type = DadosInstanciaProcessoDTO.class;
info.name = "iniciarExecucaoProcessoComTicketResult";
break;
}
}
}
--
package data;
import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class KeyValue implements KvmSerializable {
private String sKey = "";
private String sValue = "";
public KeyValue(String k, String v){
this.sKey = k; this.sValue = v;
}
public Object getProperty(int i) {
switch (i) {
case 0: return sKey;
case 1: return sValue;
}
return null;
}
public int getPropertyCount() {
return 2;
}
public void setProperty(int i, Object o) {
switch (i) {
case 0: this.sKey = o.toString(); break;
case 1: this.sValue = o.toString(); break;
}
}
public void getPropertyInfo(int i, Hashtable hshtbl, PropertyInfo pi) {
switch (i) {
case 0:
pi.name = "key"; pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
pi.type = PropertyInfo.STRING_CLASS;
break;
case 1:
pi.name = "value"; pi.namespace = "http://schemas.datacontract.org/2004/07/MyWS.WS.EXT";
pi.type = PropertyInfo.OBJECT_CLASS;
break;
}
}
}
You must add the getters and setters to all the classes that implement KvmSerializable.