Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:41:02+00:00 2026-05-25T11:41:02+00:00

I’m building an application which requires connection with server with post method and gets

  • 0

I’m building an application which requires connection with server with post method and gets the result. I need to get the particular part of the server response and convert it to different types of primitives (from String to short, int, byte etc.)

So basically I need to get a part of the response code and convert it to short, than see if there is an enum element with this value.But the problem is that the response returns value 001 and after I convert it to short and pass it to my getByValue(int) method in enum, it’s saying me that there is no element with 001. If i print the short value I get 1.

Here is a sample of code which I’m using :

                httppost.setEntity(new UrlEncodedFormEntity(postParameters));

            HttpResponse response = httpclient.execute(httppost);
            Log.v("Response ","Status line : "+ response.getStatusLine().toString());
            String responseBody = EntityUtils.toString(response.getEntity()); //response
            Log.v("Response ","Response : "+ responseBody);

            int objectIdentificator = Integer.parseInt(responseBody.substring(0,32));
            Log.v("Response ","Object Identificator (LONGINT) : "+ responseBody.substring(0,32));
            Log.v("Response ","Object Identificator (LONGINT) : "+ objectIdentificator);

            String type = responseBody.substring(32,35);
            Log.v("Response ","TYPE (UNSIGNED BYTE) : "+ type);
            short pType = Short.parseShort(type); // short 
            Log.v("Response ","TYPE (UNSIGNED BYTE) : "+ pType);

            String operation = responseBody.substring(35,38); //
            short operationType = Short.parseShort(operation);
            Log.v("Response ","OPERATION (UNSIGNED BYTE) : "+ operation);
            Log.v("Response ","OPERATION (UNSIGNED BYTE) : "+ operationType);

            String objectId = responseBody.substring(38, 70);
            Log.v("Response ","UID (CHAR, length 32) : "+ objectId);

            int id = Integer.parseInt(responseBody.substring(70, 102));
            Log.v("Response ","ID (LONGINT) : "+ responseBody.substring(70, 102));
            Log.v("Response ","ID (LONGINT) : "+ id);

            String size = responseBody.substring(102,134);          
            Log.v("Response ","Data Size (LONGINT) : "+ size);

            String hash = responseBody.substring(134,166);
            Log.v("Response ","Data Hash (CHAR, length 32 : "+ hash);

            String  dType = responseBody.substring(166,169);
            Log.v("Response ","Data Type (UNSIGNED BYTE) : "+ dType);
            short dataType = Short.parseShort(dType);
            Log.v("Response ","Data Type (UNSIGNED BYTE) : "+ dataType);

            String data = responseBody.substring(169, responseBody.length());
            Log.v("Response ","Data (CHAR, any length, in BASE64) : "+ data);

            byte[] first = Base64.decode(data);
            String string = new String(first, "UTF-8");

            Log.v("Response ","BASE 64 : "+ string);


            RPCPacket packet = new RPCPacket(   objectIdentificator,
                                                RPCPacketType.getPacketTypeByValue(pType),
                                                RPCOperationType.getByValue(Integer.parseInt(operation)),
                                                objectId,
                                                id,
                                                Integer.parseInt(size),
                                                hash,
                                                RPCPacketDataType.getByValue(dataType),
                                                first
                                                );


            Log.v("PacketType", "RPCPacketType : "+packet.packetTypeToStr(RPCPacketType.getPacketTypeByValue(pType)));

And packetTypeToStr code :

public String packetTypeToStr(RPCPacketType type){

        String str=null;
        switch(type){
        case ST_OBJECT_TYPE_INFO_START: 
                str = "ST_OBJECT_TYPE_INFO_START"; 
            break;
        case ST_OBJECT_TYPE_INFO_ERROR: 
                str = "ST_OBJECT_TYPE_INFO_ERROR"; 
            break;
        case ST_OBJECT_TYPE_COLLECTION: 
                str = "ST_OBJECT_TYPE_COLLECTION"; 
            break;
        case ST_OBJECT_TYPE_CATEGORY: 
                str = "ST_OBJECT_TYPE_CATEGORY";
            break;
        case ST_OBJECT_TYPE_CARD: 
                str = "ST_OBJECT_TYPE_CARD"; 
            break;
        case ST_OBJECT_TYPE_MESSAGE: 
                str = "ST_OBJECT_TYPE_MESSAGE"; 
            break;
        case ST_OBJECT_TYPE_GENRE: 
                str = "ST_OBJECT_TYPE_GENRE"; 
            break;
        case ST_OBJECT_TYPE_TAG: 
                str = "ST_OBJECT_TYPE_TAG"; 
            break;
        case ST_OBJECT_TYPE_USER: 
                str = "ST_OBJECT_TYPE_USER"; 
            break;
        case ST_OBJECT_TYPE_MEDIA_COLLECTION: 
                str = "ST_OBJECT_TYPE_MEDIA_COLLECTION"; 
            break;
        case ST_OBJECT_TYPE_MEDIA_CATEGORY: 
                str = "ST_OBJECT_TYPE_MEDIA_CATEGORY"; 
            break;
        case ST_OBJECT_TYPE_MEDIA_CARD: 
                str = "ST_OBJECT_TYPE_MEDIA_CARD"; 
            break;
        case ST_OBJECT_TYPE_MEDIA_TAG: 
                str = "ST_OBJECT_TYPE_MEDIA_TAG"; 
            break;
        case ST_OBJECT_TYPE_INFO_END: 
                str = "ST_OBJECT_TYPE_INFO_END"; 
            break;
        case ST_OBJECT_TYPE_CARDSTATS_CATEGORY: 
                str = "ST_OBJECT_TYPE_CARDSTATS_CATEGORY"; 
            break;
        case ST_OBJECT_TYPE_CONTENT: 
                str = "ST_OBJECT_TYPE_CONTENT"; 
            break;
        case ST_OBJECT_TYPE_MEDIA_COLLECTION_BUTTON: 
                str = "ST_OBJECT_TYPE_MEDIA_COLLECTION_BUTTON"; 
            break;
        default: 
                str ="UNKNOWN "+type;
            break;
        }

        return str;
    }

And the exception :

09-08 09:53:08.744: WARN/System.err(2509): java.lang.IllegalArgumentException: no datatype with 001 exists
09-08 09:53:08.754: WARN/System.err(2509):     at com.stampii.stampii.comm.rpc.RPCCommucatorDefines$RPCOperationType.getByValue(RPCCommucatorDefines.java:34)
09-08 09:53:08.754: WARN/System.err(2509):     at com.stampii.stampii.user.UserLogin$2.onClick(UserLogin.java:122)
09-08 09:53:08.754: WARN/System.err(2509):     at android.view.View.performClick(View.java:2408)
09-08 09:53:08.754: WARN/System.err(2509):     at android.view.View$PerformClick.run(View.java:8817)
09-08 09:53:08.754: WARN/System.err(2509):     at android.os.Handler.handleCallback(Handler.java:587)
09-08 09:53:08.754: WARN/System.err(2509):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-08 09:53:08.754: WARN/System.err(2509):     at android.os.Looper.loop(Looper.java:144)
09-08 09:53:08.754: WARN/System.err(2509):     at android.app.ActivityThread.main(ActivityThread.java:4937)
09-08 09:53:08.754: WARN/System.err(2509):     at java.lang.reflect.Method.invokeNative(Native Method)
09-08 09:53:08.754: WARN/System.err(2509):     at java.lang.reflect.Method.invoke(Method.java:521)
09-08 09:53:08.754: WARN/System.err(2509):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-08 09:53:08.764: WARN/System.err(2509):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-08 09:53:08.764: WARN/System.err(2509):     at dalvik.system.NativeStart.main(Native Method)

RPCOperationType code :

public enum RPCOperationType {
        O_CREATE(1),
        O_UPDATE(2),
        O_DELETE(3);

        private int value;
        private intvalue1;
        private RPCOperationType(int i){
            this.value=i;
        }
        public int getNumericType(){
            return value;
        }
        public static RPCOperationType getByValue(int i) {
             for(RPCOperationType dt : RPCOperationType.values()) {
                 if(dt.value1 == i) {
                     return dt;
                 }
             }
             throw new IllegalArgumentException("no datatype with " + i + " exists");
         }

    }

So any suggestions how can I solve this issue without changing the id’s in enum?
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:41:03+00:00Added an answer on May 25, 2026 at 11:41 am

    The exception is not thrown by the code you showed us. The stack trace says where the exception occurs:

    at com.stampii.stampii.comm.rpc.RPCCommucatorDefines$RPCOperationType.getByValue(RPCCommucatorDefines.java:34)
    

    It’s thus the call to RPCOperationType.getByValue() in RPCCommucatorDefines.java, at line 34 that throws this exception. You’re certainly passing it a String, and not an int, BTW, because there is no way for a short variable to be printed as 001 as it’s done in the error message of the exception.

    The two first lines of a stack traces are the most important one. The first one telle you what’s wrong, and the second line tells you where the exception is thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.