Convert byte to string - not working

Hello. I'm having trouble figuring out this conversion. I want to check if a byte from a byte array is equal to a specified string (or character). This is the code that I have:
byte byteArray[] = new byte[3];
byte tempByte = byteArray[2];
String tempString = tempByte.toString();
The compilation error that I'm getting: byte cannot be dereferenced
If you have any idea what I should do to fix this, please let me know.
c00p

Use this line instead:
String tempString = Byte.toString(tempByte);
You can't call a method on a primitive type of byte.

Similar Messages

  • How to convert byte into string

    can any tell me how to convert byte into string
    when im an debugging thid code in eclipse it shows the result in integer format instead of string but in command prompt it is showing result in string format..........plz help
    package str;
    import java.io.*;
    public class Testfile {
    public static void main(String rags[])
    byte b[]=new byte[100];
    try{
    FileInputStream file=new FileInputStream("abc.txt");
    file.read(b,0,50);
    catch(Exception e)
         System.out.println("Exception is:"+e);
    System.out.println(b);
    String str=new String(b);
    System.out.println(str);
    }

    Namrata.Kakkar wrote:
    errors: count cannot be resolved and Unhandled exception type Unsupported Encoding Exception.
    If i write an integer value instead of "count" then Unhandled exception type Unsupported Encoding Exception error is left.This is elementary. You need to go back to [http://java.sun.com/docs/books/tutorial/|http://java.sun.com/docs/books/tutorial/] .

  • Number to fractional string not working correctly

    I am measuring some parameters from oscillsocpe. i need to write these values to text file for which i am using write to spreadsheet, but what is happening is it is always writing zero value to file, on debugging i found that while converting from number to string it is always writng zero to string indicator, then separately i used that number to fractional string indicator and it is always showing zero in string output , i dont why it is happening.
    Attached below is the code.
    Solved!
    Go to Solution.
    Attachments:
    Time meas sub.vi ‏31 KB

    Ranjeet Singh and Norbert_B
    Thanks for ther reply
    Ranjeet singh,
    number to fractional string is working correctly, there is some other problem, because inly when i am executing this code converting this rise time value to string then only it is showing zero, otherwise for any random number if i am checking this number to fractional string is working correctly.
    Norbert_B
    i dont need to convert it back to string that i am doing only to check why it is showing zero value on converting number to string , because when i was writing to spreadsheet file it was always writing zero value, so when checked that code it was observed that while converting from array of numbers to spreadsheet string it is always writing zero value that's why i am doing it here just to check why it is not converting to string, but your suggestion helped in focussing the string that i am gettong from VISA read, i can use that  in last case if i wont be able to find the solution but main problem is that why i am not able to convert it back to string, why it is showing zero because it is because of this only write to spreadsheet is always showing zero value .

  • I bought Smart Photo Converter which do,s not work but i can't get any refund , i have contacted the company but no reply and that was two weeks ago...so do you talk to someone at the App store?

    I bought Smart Photo Converter which does not work but i can't get any refund , i have contacted the company but no reply and that was two weeks ago...so do you talk to someone at the App store?

    Mac App Store Support -
    http://www.apple.com/support/mac/app-store/

  • NXT Flatten to String Not Working with Clusters and Arrays

    Hello,
    My name is Joshua and I am from the FIRST Tech Challenge Team 4318, Green Machine. We are trying to write a program that will write to a configuration file and read it back. The idea is that we will be able to write to a config file from our computer that will be read by our autonomous program when it runs. This will define what the autonomous program does.
    The easiest way to do this seems to be flattening a data structure to a string, saving it to a file, and then reading back and unflattening it. The issue is that the flatten to string and unflatten from string VIs don't seem to work with arrays and clusters on the NXT. It does work when running on the computer. We've tried arrays, clusters, clusters in arrays and arrays in clusters, none seem to work. Thinking it was something to do with reading the string from a file, we tried bypassing the file functionality, still not working. It does work with basic data types though, such as strings and numbers.
    No error is thrown from what we can tell. All you get is a blank data structure out of the unflatten VI.
    The program attached is a test program I've been working on to get this functionality to work. It will display the hex content of what is going into the file, coming out of the file, and then the resulting data from the unflatten string, as well as any errors that have been thrown. The data type we are using simulates what we would like to store. There is also a file length in and out counter. The out file is a little larger because the NXT write file VI adds a new line character on to the end (thus the use of the strip white space VI). This character was corrupting even basic data types saved to file.
    I would like to know if there is a problem with what we are doing, or if it is simply not possible to flatten arrays on the NXT. Please ask if you have any questions about the code. Thank you in advanced!
    Joshua
    Attachments:
    ReadableTest.vi ‏20 KB

    Hi jfireball,
    This is a very interesting situation. Take a look at what kbbersch said. I also urge you to post in the FTC Forums. You posted your question to the general LabVIEW forums, but by posting to the FTC Forums, you will have access to others that are using the NXT hardware.
    David B.
    Applications Engineer
    National Instruments

  • EBS Search String not working

    Hi All
    I am doing configuration for an EBS implementation in development system. I have configured couple of search strings and 2 of them are not producing desired result. Please have a look.
    1. BAI2 file has following information
    16,699,12100,V,140710,,0000001159,1159/
    88,FR:RETURN OF MICR CHEQUE DEPOSIT
    I have created search string ZDDRETURNIN with search string as follows
    R                               -> Z
    E                               -> D
    T                               -> D
    U                              -> R
    R
    N OF MICR CHEQUE DEPOSIT
    Search string use:-
    CC  xxxx House Bank YYYYY Acc Id CHECK
    Interpretation Alogirthm "All Interpretation Algorithms"
    Target Field "Posting Rule"
    699 code is assigned to posting rule ZBCH. This BAI code is sent by Citibank in 3 scenarios. For two scenarios, I have tried to replace posting rule ZBCH with some other value. In one case search string works, but it did not work in above case. Above example produced posting to ZBCH posting rule instead of ZDDR.
    2.)
    BAI2 file has following information
    16,495,4651810362,V,140709,,3034086283,XXXX LT/
    88,FR:FT OUTGOING - SWIFT
    I have created search string ZOFXPMTIN with search string as follows
    F  -> Z
    T  -> C
       ->  K
    O -> O
    U
    T
    G
    O
    I
    N
    G - SWIFT
    Activated search string as for previous one
    495 bai code is assigned to posting rule ZOEF. This BAI code is sent by Citibank in 2 scenarios. For above scenario, I have tried to replace posting rule ZOEF with ZCKO. But it did not work. In above case, system tried to process record using posting rule ZOEF instead of ZCKO.
    Can you please tell why system is not able to select desired posting rule for processing ? Appreciate feedback.
    -Thanks
    Kapil

    Hi  Kapil .
    1. BAI2 file has following information
    16,699,12100,V,140710,,0000001159,1159/
    88,FR:RETURN OF MICR CHEQUE DEPOSIT
    I have created search string ZDDRETURNIN with search string as follows
    R                               -> Z
    E                               -> D
    T                               -> D
    U                              -> R
    R
    N OF MICR CHEQUE DEPOSIT
    Search string use:-
    CC  xxxx House Bank YYYYY Acc Id CHECK
    Interpretation Alogirthm "All Interpretation Algorithms"
    Target Field "Posting Rule"- CAN YOU PLEASE CHECK THAT ZDDR IS YOUR POSTING RULE . IF YOUR TARGET FIELD IS POSTING RULE THEN YPOU NEED TO ASSIGN YOUR POSTING RULE IN PLACE OF ZDDR . PLEASE ASSIGN YOUR POSTING RULE HERE THIS WILL WORK
    MANY THANKS

  • Converting to PDF is not working

    I pay a monthly fee to be able to convert documents to PDF, but it has not been working.  The 1st 3 documents I converted several months ago were a breeze, but since then going through the same procedure is completely unsuccessful.  All it does is say "uploading" and never goes any further.  Is there any way to get this fixed, or if not how on earth do I find a way to contact this company to cancel my subscription/license?  I can't keep paying for something that does not work.

    Hi jkreed2,
    We would like to help!
    1) What type of doc are you converting to PDF? How large is the document?
    2) Here is how to manage your subscription:
    *Sign in <, in the top right corner using your Adobe.com credentials
    *Click on your name (same location) and select ‘My products and services’
    *From there you can check on your status, log in/account info, update/cxl, etc.
    Looking forward to hearing back from you!
    Regards, Stacy

  • LSMW For Converting Open Sales Orders (not working for more than 1 item)

    Hi,
    I am using following standard object for Open sales orders .
    Object               0090   Sales documents                   
    Method               0000                                     
    Program Name         RVINVB10                                 
    Program Type         D   Direct Input                         
    Its not working for more than 1 line item.
    For more than 1 line item its giving Error saying that
    '102122                         V1                   845
    Print parameter SAPML2 1 is not defined
    Can anybody help me out in this regard.
    Thanks in advance.
    Nitin.

    hello, friend.
    i will still research the subject.  but the first thing that comes into my mind is t-code VA05.  with this, you have the option to change the Plant en masse.  so a possible workaround is for you to list a number of sales orders using VA05.  you then sort the line items by Plant.  choose all items with the same plant, change the plant via mass change... then change back to the original plant.  hopefully, the new settings should apply.
    do test a few sales orders by doing this for a larger scope.
    regards.

  • Convert PDF to WORD not working

    Just purchased ExportPDF - can't convert PDF file to WORD document. the "CONVERT" button on screen not activated.

    Hi Nolan,
    I check the subscription status under the email Id you provided also for security reason i delete the Email id from your previous post.
    I wasn't able to find any subscription under that email id. Please provide me the other email id if you have choose the other one while subscribing for ExportPDF service
    Please visit below mentioned forum thread to send private message to send your personal Information.
    http://forums.adobe.com/thread/1184148
    Regards,
    Ajlan Huda.

  • Problems converting byte[] to string

    I use
    byte[] encryptedBytes = cipher.doFinal(bytesToEncrypt);
    String Ciphertext = new String(encryptedBytes);
    and sometimes i get the correct answer ans sometimes no. If yo want the code is in this post:
    http://forum.java.sun.com/thread.jspa?threadID=790137&start=15&tstart=0

    That's because the C language lacks true character and string data types. It only has arrays of bytes. Unfortunately in C bytes are misleadingly called "chars."
    It works if you put ASCII because byte sequences that correspond to ASCII characters can, on most systems, be safely converted to characters and strings. You see, conversions from bytes to characters are done using things called "encoding schemes" or just encodings. If you don't specify an encoding, the system's default is used. The default encoding can be pretty much anything so it's best not to assume much about it.
    You can also use a fixed encoding, like this:String Ciphertext = new String(encryptedBytes, "ISO-8859-1");Just remember that when you convert the string back to bytes you have to use the same encoding again, that isbyte[] cipherBytes = cipherString.getBytes("ISO-8859-1");

  • How do I convert byte[] to String?

    I've got a class that pulls information from a GPS receiver on a COM port. That works fine, but the information I'm getting from the port is in the following format:
    Reading serial port...
    44,44,52,46,50,44,77,44,45,51,52,46,50,44,77,44,44,48,48,48,48,42,120,30,-104,-128,96,120,96,0,-26,126,-98,-104,-98,0,30,-122,6,30,-122,6,120,-122,-32,-122,-32,-122,-32,-122,-32,-122,-32,-122,-32,-122,-32,-122,-32,-122,-32,-122,-32,120,-122,-32,-122,-32,-122,-32,-122,-104,-122,6,120,6,-98,30,-104,-128,96,120,96,0,-26,24,-26,-26,-104,30,30,-122,24,120,-32,120,30,102,120,-26,120,-26,-4,48,50,52,44,86,44,52,48,53,54,46,49,50,50,49,44,78,44,48,55,51,53,52,38,54,70,70,-58,118,-115,25,25,89,70,6,102,6,-122,-58,-58,-58,-26,83,102,-122,
    -61,-31,
    36,71,80,71,71,65,44,50,49,52,53,53,54,46,48,50,52,44,52,48,53,54,46,49,50,50,49,44,78,44,48,55,51,53,52,46,50,51,52,52,44,87,44,48,44,48,48,44,44,52,46,50,44,77,44,45,51,52,46,50,44,77,44,44,48,48,48,48,42,52,66,13,10,36,71,80,71,83,
    65,So it's pretty obvious that it's spitting out ASCII values, so I changed the code a bit to print out the corresponding letters instead:
    Reading serial port...
    $GPGGA,214724.031,4056.1221,N,07354.2344,W,0,00,,4.2,M,-34.2,M,,0000*48
    $GPGSA,A,1,,,,,,,,,,,,,,,*1E
    $GPGSV,3,1,11,31,70,286,,14,57,089,,32,51,293,,30,44,061,*7D
    $GPGSV,3,2,11,05,24,046,,22,23,167,,20,20,315,,16,15,194,*70
    $GPGSV,3,3,11,12,12,039,,29,09,103,,11,00,279,*4F
    $GPRMC,214724.031,V,4056.1221,N,07354.2344,W,,,140608,,,N*68
    $GPGGA,214725.031,4056.1221,N,07354.2344,W,0,00,,4.2,M,-34.2,M,,0000*49
    $GPGSA,A,1,,,,,,,,,,,,,,,*1ENow those are the NMEA sentences that the GPS receiver spits out, that's exactly what I need. Only problem is I'm printing them out using the following code:
          byte[] buffer = new byte[4096];
          InputStream theInput = thePort.getInputStream();
          System.out.println("Reading serial port...");
          while (canRead()) // Loop
            int bytesRead = theInput.read(buffer);
            if (bytesRead == -1)
              break;
            for (int z = 0; z < bytesRead; z++)
                 System.out.print(Character.toString((char)buffer[z]));
            }So as you can see, it's simply taking the byte, converting it from ASCII to a symbol or letter, and putting it on the screen. Then it moves onto the next byte. So what I've tried to do is change it again so that it adds each converted letter to a string value, starting a completely new string every time it hits a $ sign, which always starts a NMEA sentence:
          byte[] buffer = new byte[4096];
          InputStream theInput = thePort.getInputStream();
          System.out.println("Reading serial port...");
          while (canRead()) // Loop
            int bytesRead = theInput.read(buffer);
            if (bytesRead == -1)
              break;
            String s = "";
            for (int z = 0; z < bytesRead; z++)
                 if (Character.toString((char)buffer[z]).equalsIgnoreCase("$") && s.length() > 1)
                      System.out.println(s);
                      s = Character.toString((char)buffer[z]);
                 else
                      s = s + Character.toString((char)buffer[z]);
    //             System.out.print(Character.toString((char)buffer[z]));
    s = "";
    }The problem with this is for some reason the sentences aren't whole, there's line breaks inserted into them. So when I'm passing them to the parser, I'm passing incomplete sentences. Here's the output I'm getting now:
    Reading serial port...
    $GPGSA,A,1,,,,,,,,,,,,,,,*1E
    .2,M,-34.2,M,,0000*4D
    $GPGSA,A,1,,,,,,,,,,,,,,,*1E
    ,32,51,293,,30,44,061,*7D
    $GPGSV,3,3,11,12,12,039,,29,09,103,,11,00,279,*4FHow do I get each NMEA sentence into a string so I can send it to a parser? Any ideas?
    Edited by: DeX on Jun 14, 2008 6:02 PM

    Your problem is that you're assuming a newline actually indicates the end of a line.
    Assuming you can't fix the sender (or yell at the maintainer and get him to fix it), take
    advantage of the fact that you know what a valid line starts with and just ignore the newline
    characters.
    Thanks but that gives me the same result. I think my issue is with the multithreading,
    another thread is rolling through and assigning values to the String before the previous
    thread is finished copying the bytes to it. I suggest you take advantage of the StringBuilder class. Also, if you insist on using the
    String(byte[ ]) constructor, you should note that you're assuming a charset, a rather
    dangerous thing to do. Use the String(byte[ ], String) constructor instead and explicitly use US-ASCII.

  • Ciphertext convert to readable String (NOT decryption )

    Hi,
    I have got a problem about my project, here it is....
    I have got a byte[] which is encrypted by using the DES
    I would like to convert the first 2 bytes back to READABLE string
    which will be used as a refernece.
    The way I have tried:
    1)String s = new String( byte[] b )
    2)ByteArrayOutputStream toString()
    both of them just print out the "byte" instead of "readable String"
    Can anyone help me with this??
    thx!!

    The question is "what do you want to read in the string?". It seems like you're getting the reference value of the array itself, which is most likely not what you want.
    If it's simply the numbers of the two first bytes, you can use
    String ref = array[0] + " " + array[1];If it's the character representation of a byte in the ASCII character set, you can convert it using the class Character. Example:
    String ref = new String(array, 0, 2, "ISO-8859-1"); // Use Iso Latin 1 character encodingAnd btw, this is not an advanced topic. This is basic knowledge.

  • Hyperlinks from converted excel file are not working after pdf file is moved

    I have created a pdf file from an excel file that has hyperlinks in it. The hyperlinks work fine if the files are all kept in the same exact location as the time they were created. Once the files are moved (i.e. emailed to another user) the hyperlinks no longer work. An error message pops up that the file can not be found. Is there a setting or something that I'm missing in acrobat that allows for the files to be moved, so that the hyperlinks still function properly, after creation

    No settings adjustments.
    The issue is that links, once made, have a specific path (as shown when you view the link's text string).
    When you email the files the person who recieves the email and downloads the attachments would have to have the same layout of files/folders you have.
    Without that links are "broken"
    You email a zip file that, when extracted, would create the folders/files in the required layout to reflect what you have.
    Be well...

  • Downloading DNG converter and it's not working

    I've downloaded, reinstalled, and tried several different versions of DNG converter to download my 2nd shooters Nikon D7100 RAW .NEF files, but it's not finding any images once I have it installed. I've downloaded version 7.4 for Windows, which contains the D7100 update...and I've tried installing the newer version 8.6 as well. Nothing seems to be working. What am I doing wrong?

    If you are new to the DNG converter, it's possible you are getting caught by the prompt where the converter is asking you to locate your raw files. It's only asking for the folder. Don't open the folder containing your raw images or you will get the message that there are no images to convert.

  • Converting byte to string

    Im doing a CRC for a txt file.
    So after the CRC calculation i got the 16bit check sum.
    How should i add the 16 bit to the file?
    The file is generated base on various objects. So it would be very good if i could convert the 16 bits into String and then add to the file as part of a text.

    Im suppose to add into the file, the 16 bits as 2 bytes of ASCII.
    Im doing this...
    int firstCRC = crc>>>8;
    int intSecCRC = 0x00ff & crc;
    String crc1 = ""+ (char)firstCRC;
    String crc2 = ""+ (char)intSecCRC;
    01000100 00111101 << CRC in binary
    firstCRC: D
    SecCRC : =
    So i will be appending 'D''and '=' into the file... is this correct?

Maybe you are looking for

  • Unit Testing / Integration Testing

    Hi all Can somebody provide links to SAP testing.... Can anybody define & write down the step by step details on carrying out unit testing, integration testing and user acceptance testing...How it is done..which systems..tools..test scripts / test ca

  • Trouble hooking up a PC to my wireless network

    I've been using an Airport Express for years now to broadcast wireless internet to my Mac laptop and to my roommate's Mac laptop with no problems. We even had a guest over once with a PC who was able to connect to our wireless network fine once we ch

  • Mass creation of warehouse products

    We are about to implement our first EWM storage warehouse. In classical WM we used to prepare the material master data in an Excel sheet and used the RMDATIND via LSMW for creation of the warehouse specific data. In EWM however, I found nothing simil

  • Flash call director using getURL bug

    Hi! I am using Flash 8 and Director MX 2004, and I found out that, if I use getURL("lingo: function name...") to call director function, and if there is any error happened in this function call, it seems that director won't show any error message at

  • Aftereffects reports source media is unable to be read.

    Hi all, I have a comp in AE that was working fine until yesterday when aftereffects started reporting that the source files could not be found. The problem is, the files are there and open fine in premier pro, nuke, and any other software i have trie