Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Address is invalid on local machine [on windows 8 only]

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Address is invalid on local machine [on windows 8 only]

    I am getting error on windows 8 (64bit), its working fine on windows7
    java.net.ConnectException: connect: Address is invalid on local machine or port is not valid on remote machine

    using the java code
    public static boolean linkExists(String URLName){
            URLName = "http://www.google.com";
            try {
              HttpURLConnection.setFollowRedirects(false);
              HttpURLConnection con =
                 (HttpURLConnection) new URL(URLName).openConnection();
              con.connect();
              System.out.println(con.getResponseCode());
              return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
            }
            catch (Exception e) {           
               return false;
            }
      }

    here is the stack trace
    java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
        at java.net.Socket.connect(Socket.java:579)
        at java.net.Socket.connect(Socket.java:528)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
        at sun.net.www.http.HttpClient.New(HttpClient.java:290)
        at sun.net.www.http.HttpClient.New(HttpClient.java:306)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
        at com.sls.lms.test.utilities.Utilities.linkExists(Utilities.java:70)
        at com.sls.lms.test.report.ReportTest.checkReportData(ReportTest.java:70)
        at com.sls.lms.test.report.ReportTest.CheckReportForGST(ReportTest.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
        at org.testng.junit.JUnit4TestRunner.start(JUnit4TestRunner.java:81)
        at org.testng.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:69)
        at org.testng.TestRunner$1.run(TestRunner.java:682)
        at org.testng.TestRunner.runWorkers(TestRunner.java:1012)
        at org.testng.TestRunner.privateRunJUnit(TestRunner.java:713)
        at org.testng.TestRunner.run(TestRunner.java:614)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
        at org.testng.SuiteRunner.run(SuiteRunner.java:240)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
        at org.testng.TestNG.run(TestNG.java:1031)
        at org.testng.TestNG.privateMain(TestNG.java:1338)
        at org.testng.TestNG.main(TestNG.java:1307)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    Does the code work if you put it in a small program and execute it from the commandline?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    Yes same error from command prompt

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    I can't believe the stack trace in the error message would be the same.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    java.net.ConnectException: connect: Address is invalid on local machine, or port
     is not valid on remote machine
            at java.net.DualStackPlainSocketImpl.connect0(Native Method)
            at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
            at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
            at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
            at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
            at java.net.PlainSocketImpl.connect(Unknown Source)
            at java.net.SocksSocketImpl.connect(Unknown Source)
            at java.net.Socket.connect(Unknown Source)
            at java.net.Socket.connect(Unknown Source)
            at sun.net.NetworkClient.doConnect(Unknown Source)
            at sun.net.[url]www.http.HttpClient.openServer(Unknown[/url] Source)
            at sun.net.[url]www.http.HttpClient.openServer(Unknown[/url] Source)
            at sun.net.www.http.HttpClient.<init>(Unknown Source)
            at sun.net.[url]www.http.HttpClient.New(Unknown[/url] Source)
            at sun.net.[url]www.http.HttpClient.New(Unknown[/url] Source)
            at sun.net.[url]www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown[/url]
    Source)
            at sun.net.[url]www.protocol.http.HttpURLConnection.plainConnect(Unknown[/url] Sour
    ce)
            at sun.net.[url]www.protocol.http.HttpURLConnection.connect(Unknown[/url] Source)
            at javaapplication1.JavaApplication1.linkExists(JavaApplication1.java:31
    )
            at javaapplication1.JavaApplication1.main(JavaApplication1.java:21)

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    You'll have to wait until someone with Windows 8 comes along.

    Also posted at: http://stackoverflow.com/questions/1...windows-8-only
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    Yes I first posted it on stackoverflow.com but no help so coming to Java specific forum for this...

  8. #8
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    Ok found another thing I am getting the invalid address if trying to run the code with this command
    [CODE]java -jar JavaApplication1.jar[CODE]

    but its working perfectly if I am runing the code with command
    [CODE]java -Djava.net.preferIPv4Stack=true -jar JavaApplication1.jar[CODE]

    is there anyway I can set the -Djava.net.preferIPv4Stack=true parameter globally??

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    Where does the commandline with the java command etc come from?
    Can you modify that commandline to include that option?

    For example on Windows7 and XP I can change the registry entry.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    I am not sure from where it is comming, java is installed in
    C:\Program Files\Java\jdk1.7.0
    C:\Program FIles\Java\jre

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    What you posted was paths to folders.
    What I am talking about is the commandline used to execute a java program. This is an example of a commandline:
    java -Djava.net.preferIPv4Stack=true -jar JavaApplication1.jar

    How do you execute java programs?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    I created a mini program using netbeans, its saving the .jar file of the application in /dist folder. I am running that jar file using command line
    .../JavaApplication1/dist> java -Djava.net.preferIPv4Stack=true -jar JavaApplication1.jar

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Address is invalid on local machine [on windows 8 only]

    I thought you were having a problem executing java programs. Why do you need a global setting if you are using a commandline with the needed option?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Beginner: Get Local IP address from Java applet
    By Killingeskibet in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 26th, 2013, 11:45 AM
  2. Beginner: Get Local IP address from Java applet
    By Killingeskibet in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 26th, 2013, 07:10 AM
  3. Replies: 1
    Last Post: December 5th, 2012, 06:35 AM
  4. DIRECTING TEXT OUTPUT AT THE LOCAL MACHINE
    By jai in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: December 20th, 2011, 12:13 AM
  5. Moving MySql Database from one machine to another machine
    By vaishali in forum JDBC & Databases
    Replies: 5
    Last Post: July 21st, 2010, 01:21 AM