Messing with Class String. Error in the code that i can't figure out..

There is an error in my code that i just can't seem to figure out. I've tried debbugin it but it seems to work when i do it by hand but when running it gives me the wrong value.... I will put part of the code and comment what i'm trying to do... Basically the whole idea of that part is to get an ip address from an input but for now i will consider putting in the IP Address. It should not exceed more than 4bytes so the max is 256.256.256.256
After that i have to seperate the "." from it and take each string seperately and see if it's greater than 256 than finally copy it into an array of bytes.... Here is the code..
//CODE//
NewIPAddress = ipText.getText();// Consider this for now as "10.1.1.127"
int x=0, y=0, i=0, z=0;
boolean error=false;
String IPString;
byte[] buffer = new byte[4];
int byteVal;
do
x=NewIPAddress.indexOf(".",z);
// This should get the first occurance
// in the third round it gives the
// wrong value i dont know why....
// If there is no occurance it returns
// -1
if(x!=-1)
IPString = NewIPAddress.substring(y,(x+z));
// I get the value one
// by one 10, 1, 1 ,127
byteVal=Integer.parseInt(IPString);
buffer=(byte)byteVal;
z=z+x;
y=z+1;
i++;
if(byteVal>256)
//If each value is greater than 256 then it's
//an error
JOptionPane.showMessageDialog(null,"Not a valid IP format","Error",JOptionPane.ERROR_MESSAGE);
break;
else
error=true;
while(!error);
//CODE//
If u have a better way of doing it or if u know why the third error is please let me know, i'll appreciate that...

Use a StringTokenizer (java.util.StringTokenizer) in stead, and specify '.' as the separator char:
import java.util.StringTokenizer;
public class Test
     public static void main( String[] args ) throws Exception
          byte[] bytes = createIpAddressArray( "10.1.1.127" );
          System.out.println( "Byte 1: " + bytes[0] );
          System.out.println( "Byte 2: " + bytes[1] );
          System.out.println( "Byte 3: " + bytes[2] );
          System.out.println( "Byte 4: " + bytes[3] );
     public static byte[] createIpAddressArray( String ipAddress ) throws Exception
          byte [] result = new byte[ 4 ];
          StringTokenizer ipTokens = new StringTokenizer( ipAddress, "." );
          int counter = 0;
          while( ipTokens.hasMoreTokens() )
               int ipPart = Integer.parseInt( ipTokens.nextToken() );
               if( ipPart < 265 && ipPart >= 0 )
                    result[ counter++ ] = ( byte ) ipPart;
               else
                    throw new Exception( "Bad IP address." );
          return result;

Similar Messages

  • Syntax error in my code and I can't figure out the problem

    When I try to compile a program, I get this message:
    Syntax error on token "(", "Identifier" expected
    This is the part of the code that is giving me trouble:
    JTextPane textPane = createTextPane();
              JScrollPane paneScrollPane = new JScrollPane(textPane);
              paneScrollPane.setVerticalScrollBarPolicy(
                                  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              paneScrollPane.setPreferredSize(new Dimension(250, 155));
              paneScrollPane.setMinimumSize(new Dimension(10, 10));Can you see what's wrong?
    Thanks

    The code's syntax is perfectly fine. The compiler is not falgging an error message in this part of your code. One silly thing you can do:
    Try out this silly change...I don't think it will make any difference but still.
    paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);That is, put it all in a single line.
    If it is already in a single line then you can be sure that the problem is being flagged from elsewhere in your code and this portion.
    Vijay :-)

  • I'm experiencing 2 issues with a site I'm working on that I can't figure out...

    I'm developing a site for a local 5-star restaurant, and I'm almost done with the development. Unfortunately, I'm a lot better at design then coding, and I have a couple of problems that I have not found solutions to.
    If you have a few minutes, I'd love some advice on how to fix these. They are confusing me a lot...
    1) My pages have a footer that attached to the bottom of the content of the page. On pages that end with tables, there's space between the content and the footer. On pages without tables, it looks fine. Examples:
    Broken:
    [1] http://www.dorseygraphics.com/review/wclg/site_05/winelist.html
    Not broken:
    [2] http://www.dorseygraphics.com/review/wclg/site_05/contact.html
    2) My background image contains some complex elements that overlap (like vines overlapping the content area just a bit on either side). the client LOVES this, so it's not an option to remove. My background is currently a large PNG that easily takes care of the overlapping issue with a simple BG image. But it runs out at the bottom of the page, and some of the pages have content that it too tall for the background.
    Example:
    [3] http://www.dorseygraphics.com/review/wclg/site_05/reviews.html
    How would you go about solving this problem? I'm thinking the easiest way is to add a new containing DIV and use it to extend the content area down, but that would mess up the header (I think). I'm confused.

    1) My pages have a footer that attached to the bottom of the content of the page. On pages that end with tables, there's space between the content and the footer. On pages without tables, it looks fine. Examples:
    Broken:
    [1] http://www.dorseygraphics.com/review/wclg/site_05/winelist.html
    Not broken:
    [2] http://www.dorseygraphics.com/review/wclg/site_05/contact.html
    The problem here is the background image.  Do you have the image without the beige background in the center?  If so what you need to do is leave the background of the body as the URL to the image (without the beige in the center), no-repeat, and leave the color as you have.  Then move the lighter beige color background to the container with the navigation and content.
    2) My background image contains some complex elements that overlap (like vines overlapping the content area just a bit on either side). the client LOVES this, so it's not an option to remove. My background is currently a large PNG that easily takes care of the overlapping issue with a simple BG image. But it runs out at the bottom of the page, and some of the pages have content that it too tall for the background.
    Example:
    [3] http://www.dorseygraphics.com/review/wclg/site_05/reviews.html
    How would you go about solving this problem? I'm thinking the easiest way is to add a new containing DIV and use it to extend the content area down, but that would mess up the header (I think). I'm confused.
    If you look at my above answer I don't think this is a huge problem.  In CSS3 (Safari, Firefox, Chrome, IE9) you can have multiple background images, one static and one repeating in your case.  However, older browsers will not see this, most notably IE 8 and earlier.  You could put the initial image in one layer and make the body background a repeating image but you run the risk of the layers not aligning. 
    Another alternative is to set the max-height of the content container and then set the overflow attribute to scroll in the CSS (overflow: scroll;).  That would make the content container scroll independantly from the page.
    A final alternative would be to discuss the pages with the client again.  For instance with the wine list there are different types of wines.  You could have nested tabbed panels, or you could make a page for each wine type sparkling/white, red, etc. and then have tabbed panels underneath to make the lists shorter.  Otherwise the "Significant Others" or "Riesling" get lost at the bottom of the page, regardless of your background, and users do not know those wines are offered.

  • With the new update, I can't figure out how to merge duplicate "Faces" files together, so I end up with one location per face.

    With the newest update, I can't figure out how to merge duplicate files in "Faces" (iPhoto).  I have more than one file going for a face, and use to be able to click and drag them into merging.  Can't seem to do it now.  Can anyone please help?  Thanks

    Are you talking about iPhoto or Photos? If Photos, do you mean that Photos has several files for the same person but they are labeled differently and you are trying to merge them as one? If so, then you have to rename one of the files to match the other one with the correct name.  If this is not what you mean then could you explain more clearly what you mean. To give an example if I click on Faces and Photos shows me all named faces in the top and on the bottom there are suggested faces that can be dragged onto a face in the top level to merge.  If you try to merge two face groups in the top level that are the same person but for some reason the faces are labeled differently you have to label them with the name you want to use and then they will automatically merge.

  • Newbie for the life of me can't figure out where in contact.php you tell it where to send form?

    Thx for any help.
    I know it's got to be so obbvious.
    Why would you send in php vs html?
    <?php
    if(!$_POST) exit;
    $email = $_POST['email'];
    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
    if($errors==1) echo $error;
    else{
    $values = array ('name','email','message');
    $required = array('name','email','message');
    $your_email = "[email protected]";
    $email_subject = "New Message: ".$_POST['subject'];
    $email_content = "new message:\n";
    foreach($values as $key => $value){
       if(in_array($value,$required)){
      if ($key != 'subject' && $key != 'company') {
        if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
      $email_content .= $value.': '.$_POST[$value]."\n";
    if(@mail($your_email,$email_subject,$email_content)) {
      echo 'Message sent!';
    } else {
      echo 'ERROR!';
    ?>

    Thanks. I'm working with different hosts and I guess thats where the confusion for me is coming in. In bluehost, I simply submit my form through form action to http://www.bluehost/bluemail. With the php form construction it 's form action is contact.php. Does this mean that the server I'm working with will uinderstand how to process contact.php and where to send it based on paramaters previously submitted? Or do I instruct the server via the php form? Thanks again
    Date: Wed, 8 Feb 2012 13:50:11 -0700
    From: [email protected]
    To: [email protected]
    Subject: Newbie for the life of me can't figure out where in contact.php you tell it where to send form?
        Re: Newbie for the life of me can't figure out where in contact.php you tell it where to send form?
        created by mhollis55 in Dreamweaver - View the full discussion
    The reason why this is done in php is because php is server-side scripting. It's telling your server to do stuff. HTML doesn't tell your server anything, it tells the client (the web browser loading it) to do things. Only your server can send an email.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4194407#4194407
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4194407#4194407. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Dreamweaver by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • I am having trouble setting up icloud it keeps sending me back to install instructions and I'm just getting frustrated. So far I'm not liking the new itunes I can't figure out how to  look at my duplicate music like I used to.

    I can't sign on to icloud. It says I need an icloud account. I click the help option it send me back to the same page. I reinstall it nothing.
    Download the iCloud Control Panel.
    To enable iCloud on your Windows PC, first set up iCloud on your other devices, then install the iCloud Control Panel for Windows (Windows Vista with Service Pack 2 or Windows 7 required).
    ok I can't seem to set up iCloud on any device I don't understand... Ive already installed it three times.
    Turn on iCloud.
    From the Windows Start menu, choose iCloud Control Panel.
    Enter the Apple ID you used to create your iCloud account and select the iCloud services you’d like to enable.
    For mail, contacts, and calendars, you can use iCloud.com or Outlook 2007 or later.
    there is no iCloud control panel but I click on i cloud. Then entere the Apple ID you used to create your iCloud account - WHAT!!!!? where is this I keep trying to find out how to create and iCloud account but I keep getting these stupid directions!!!
    Enable automatic downloads.
    To enable automatic downloads for your music, apps, and books, open iTunes > Edit > Preferences > Store and select Music, Apps, and Books.* (Requires iTunes 10.5 or later.)
    - This is the only step that makes sense and already did it...
    Turn on iCloud for the rest of your devices.
    To get the most out of iCloud, set it up everywhere.
    This is soooo frustrating!!!!
    Also I want to be able to look at duplicate songs on my itunes but after I downloaded the new version I can not figure out how to get that back. If the duplicate setting isn't in the new itunes I want the old version back.

    Did you ever resolve the iCloud problem.I am in the same position and its driving me mad!!! If you have a link to an solution I would appreciate it.

  • I have lost my "Basic" panel in the Develop module and can't figure out how to get it back. My right panel goes from the Histogram straight to the Tone Curve panel.  My Basic panel should be below the Histogram.  Any ideas how to get it back.  I have even

    I have lost my "Basic" panel in the Develop module and can't figure out how to get it back. My right panel goes from the Histogram straight to the Tone Curve panel.  My Basic panel should be below the Histogram.  Any ideas how to get it back.  I have even uninstalled my lightroom and reinstalled it with same issue.  Help!!!

    Right click on or near one of the other headers and a pop-up will appear and you will be able to select the Basic Panel for viewing.

  • Hi. I just downloaded "angry birds" from the iTunes store. It says it was successfully downloaded and that I can use it on the two mac products I have. I can see an icon for it in the finder on the mac, but I can't figure out how to play the game. Anyone?

    Hi. I just downloaded "angry birds" from the iTunes store. It says it was successfully downloaded and that I can use it on the two mac products I have. I can see an icon for it in the finder on the mac, but I can't figure out how to play the game. Anyone?

    Thank you for your reply. After a lot of fruitless searches, I hit on a page that offered the same wisdom you did. I feel like rather a fool for not knowing that. Grr. I really appreciate your answer, and that you didn't end it with "dummy." Cheers to you. Hope someone does something kind for you today.

  • HT1719 My shuffle is not syncing all of the selected songs & I can't figure out how to get it to sync all the checked songs. Please help!

    My shuffle is not syncing all of the selected songs & I can't figure out how to get it to sync all the checked songs (syncs some, but not others). Please help!

    Perhaps this article can help.
    Syncing music to iPod shuffle
    B-rock

  • When recording voiceovers, I click the stop recording button at the end, but I can't figure out how to get rid of the "click" sound before I send off the recording!

    When recording voiceovers, I click the stop recording button at the end, but I can't figure out how to get rid of the "click" sound before I send off the recording!

    njordan wrote:
    I can't figure out how to get rid of the "click" sound before I send off the recording!
    drag the BottomRight edge of the region to the left, past the unwanted sound

  • Ever since I updated my OS, the screen on my Mac will automatically become huge if I keep my mouse on the screen. I can't figure out how to return the screen to a normal size. Any help?

    Ever since I updated my OS, the screen on my Mac will automatically become huge if I keep my mouse on the screen. I can't figure out how to return the screen to a normal size. Any help?

    Hold down the 'ctrl' key and scroll backwards on the mouse.
    Then go to System Preferences > Universal Access > Seeing. Turn off the Zoom feature.
    Similarly in Sys Pref > Mouse uncheck the box for 'Zoom using scroll wheel…'
    If it still occurs after that there may be a corrupt .plist file.

  • The vfs_fsevents.c file is kicking out errors that I can not figure out.

    I get errors that I tracked back to the vfs_fsevents.c file. But I can not figure out of these are errors I need to worry about or just random. Below are the errors that I am getting.
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unable to get path for vp 0xdc8eafc (tmp.live.6.cmpt..mds.101.96.compactPayloads2.idx; ret 22; type 4)
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unabled to get a path for vp 0xdc8eafc.  dropping the event.
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unable to get path for vp 0xdd47158 (tmp.live.6.cmpt..mds.101.95.compactPayloads1.idx; ret 22; type 4)
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unabled to get a path for vp 0xdd47158.  dropping the event.
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unable to get path for vp 0x173da534 (tmp.live.6.cmpt..mds.101.97.compactPayloads1.idx; ret 22; type 4)
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unabled to get a path for vp 0x173da534.  dropping the event.
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unable to get path for vp 0xbeabd7c (tmp.live.6.cmpt..mds.101.98.compactPayloads2.idx; ret 22; type 4)
    5/9/12 12:59:12.000 PM kernel: add_fsevent: unabled to get a path for vp 0xbeabd7c.  dropping the event.
    5/9/12 1:00:51.000 PM kernel: add_fsevent: unable to get path for vp 0x17ebc280 (journalAttr.231; ret 22; type 4)
    5/9/12 1:00:51.000 PM kernel: add_fsevent: unabled to get a path for vp 0x17ebc280.  dropping the event.
    If anyone can point me in the right direction I would appreciate it.
    Thanks,
    Kevin Rosenthal

    Melissa,
    Yes, I now see the WAB area. Because of the horizontal tightness of the screen cap, I missed this.
    I do not have any experience with the RADEON X600, but maybe someone else knows it. My first thought would be a display driver issue with the video card. You can find out what drivers you have by following the links below. Just substitute Display Adapters for Human Interface Devices. You might go to the ATI site and see if they offer a newer driver for your video card. These get out of date in a hurry.
    As for the mouse driver there are two ways to check this out:
    1.) Control Panel>System>Hardware>Device Manager>Human Interface Devices>[Name of mouse and connection] Mouse Optical (if it is Optical)>Driver>Driver File Details. There, you will see all drviers associated with your mouse.
    2.) From the My Computer setting, search for Intelli* in Files & Folders. This will find all instances of the IntelliPoint driver. If you have it installed, then go back and do #1 above to check to see if it is in use.
    Now, all of the GUI display problems I've read of in a myriad of Adobe programs have been different, than yours. That idea is but a shot in the dark. Now, with Adobe and display issues, I normally think of Intellipoint mouse drivers. You might try changing drivers to the stock MS Windows\System32 drivers and see what happens. You might loose a touch of functionality of a multi-button/tilt-wheel mouse, if you have one, but it *might* take care of GUI issues.
    I've been hoping that someone else would chime in with "hey, that's just the xxx, don't you recognize it?" So far, no one has.
    Hunt

  • I somehow got pumpkins at the top of the screen on Firefox - can't figure out how to change them to something else. Help!

    Across the top very top of the screen I somehow loaded a seasonal picture of pumpkins. I can not find where I got them from and can't figure out how to change it to another picture.

    Sounds that you installed a Persona.<br />
    You can uninstall your current Persona and revert to the Default theme (Tools > Add-ons > Themes).
    See
    * [[Personas]]
    * [[Using themes with Firefox]]

  • I need help with Apple iCloud verification. I don't have the email and I can't figure out how to get Apple to send me a new one.

    So, in order to back up my music and stuff to the cloud I need to verify my Apple ID and I don't have the verification e-mail. If someone out there could help me out by telling me how to get Apple to send another one, or if they can, I would appreciate it alot. Thank you!!!!!

    Apple ID: Associating and verifying email addresses with your Apple ID

  • Every e-mail I get comes with a duplicate. I've tried looking at the different features of the program, but I can't figure out why this is happening. Help!

    This has been happening for several years now. After one of the updates, I started getting the duplicates. I've lived with problem for a long time because I could still get e-mails, if over abundantly. My e-mail volume has gone up and up, however, and I'm now getting 60 or 70 e-mails a day because of this problem. Can someone tell me how to fix this?

    I think I might have figured out what the problem is. I have inadvertently set up two Thunderbird accounts. When I followed your advice, I was able to open the pop folder. I also had a mail folder and opened it to find another pop folder. In both pop folders I found a popstate.dat file. When I went into account settings, I found that I had somehow set up two cbldw accounts. The one at the top said mail as incoming server. The second account showed pop as the incoming server. Now this is what perplexes me. Do I attempt to get rid of one of the accounts? I took both popstate.dat files out of the folders and put them on my desktop. When I went back into the two mail folders, behold, the popstate. dat files were still in the folder, having been altered at the time I took them out of the folders.
    I'm really in a quandary as to how to proceed. I'm not sure I can delete the second Thunderbird account without wrecking havoc on my primary e-mail source, and there are a few subtle differences in the two different preferences sections.
    Any helpful suggestions?

Maybe you are looking for