Error in code..please help

Hi,
I'm writing a SIP messaging klient and i am having problem with connecting the client to my SIP-server (OpenSER)
javax.sip.InvalidArgumentException: 300:[email protected]: 300:[email protected]
at gov.nist.javax.sip.SipStackImpl.createListeningPoint(SipStackImpl.java:645)
at sipTrade.createProvider(sip.java:274)
at sipTrade.main(sip.java:299)
Caused by: java.net.UnknownHostException: 300:[email protected]: 300:[email protected]
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at gov.nist.javax.sip.SipStackImpl.createListeningPoint(SipStackImpl.java:625)
... 2 more
import java.io.*;
import javax.sip.*;
import javax.sip.address.*;
import javax.sip.header.*;
import javax.sip.message.*;
import java.util.*;
public class sip implements SipListener {
     private static AddressFactory addressFactory;
     private static MessageFactory messageFactory;
     private static HeaderFactory headerFactory;
     private static SipStack sipStack;
     private int port;
     protected SipProvider udpProvider;
     protected Dialog dialog;
     protected int notifyCount = 0;
     protected final String serverIP = "300:[email protected]";
     class MyEventSource implements Runnable {
          private sipTrade st;
          private EventHeader eventHeader;
          public MyEventSource(sipTrade notifier, EventHeader eventHeader ) {
               this.st = notifier;
               this.eventHeader = eventHeader;
          public void run() {
               try {
                    for (int i = 0; i < 100; i++) {
                         Thread.sleep(100);
                         Request request = this.st.dialog.createRequest(Request.NOTIFY);
                         SubscriptionStateHeader subscriptionState = headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
                         request.addHeader(subscriptionState);
                         request.addHeader(eventHeader);
                         // Lets mark our Contact
                         ((SipURI)dialog.getLocalParty().getURI()).setParameter("id","not2");
                         ClientTransaction ct = udpProvider.getNewClientTransaction(request);
                         System.out.println("NOTIFY Branch ID "+((ViaHeader)request.getHeader(ViaHeader.NAME)).getParameter("branch"));
                         this.st.dialog.sendRequest(ct);
                         System.out.println("Dialog " + dialog);
                         System.out.println("Dialog state after active NOTIFY: " + dialog.getState());
                         synchronized (sipTrade.this) {
                         notifyCount ++;
               } catch (Throwable e) {
                    e.printStackTrace();
     private static void usage() {
          System.exit(0);
     public void processRequest(RequestEvent requestEvent) {
          Request request = requestEvent.getRequest();
          ServerTransaction serverTransactionId = requestEvent.getServerTransaction();
          System.out.println("\n\nRequest " + request.getMethod()+" received at " + sipStack.getStackName()+" with server transaction id " + serverTransactionId+" and dialog id "+requestEvent.getDialog());
          if (request.getMethod().equals(Request.SUBSCRIBE)) {
               processSubscribe(requestEvent, serverTransactionId);
      * Process the invite request.
     public void processSubscribe(RequestEvent requestEvent,
               ServerTransaction serverTransaction) {
          SipProvider sipProvider = (SipProvider) requestEvent.getSource();
          Request request = requestEvent.getRequest();
          try {
               System.out.println("notifier: got an Subscribe sending OK");
               System.out.println("notifier:  " + request);
               System.out.println("notifier : dialog = " + requestEvent.getDialog());
               EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
               if ( eventHeader == null) {
                    System.out.println("Cannot find event header.... dropping request.");
                    return;
               // Always create a ServerTransaction, best as early as possible in the code
               Response response = null;
               ServerTransaction st = requestEvent.getServerTransaction();               
               if (st == null) {
                    st = sipProvider.getNewServerTransaction(request);
               // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
               boolean isInitial = requestEvent.getDialog() == null;
               if ( isInitial ) {
                    // need random tags to test forking
                    String toTag = Integer.toHexString( (int) (Math.random() * Integer.MAX_VALUE) );
                    response = messageFactory.createResponse(202, request);
                    ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
                    // Sanity check: to header should not ahve a tag. Else the dialog
                    // should have matched
                    if (toHeader.getTag()!=null) {
                         System.err.println( "####ERROR: To-tag!=null but no dialog match! My dialog=" + dialog.getState() );
                    toHeader.setTag(toTag); // Application is supposed to set.
                    this.dialog = st.getDialog();
                    // subscribe dialogs do not terminate on bye.
                    this.dialog.terminateOnBye(false);
                    if (dialog != null) {
                         System.out.println("Dialog " + dialog);
                         System.out.println("Dialog state " + dialog.getState());
               } else {
                    response = messageFactory.createResponse(200, request);
               // Both 2xx response need a Contact
               Address address = addressFactory.createAddress("xTrade <sip:127.0.0.1>");
               ((SipURI)address.getURI()).setPort( udpProvider.getListeningPoint("udp").getPort() );                    
               ContactHeader contactHeader = headerFactory.createContactHeader(address);               
               response.addHeader(contactHeader);
               // Expires header is mandatory in 2xx responses to SUBSCRIBE
               ExpiresHeader expires = (ExpiresHeader) request.getHeader( ExpiresHeader.NAME );
               if (expires==null) {
                    expires = headerFactory.createExpiresHeader(30);     // rather short
               response.addHeader( expires );
               st.sendResponse(response);
                * NOTIFY requests MUST contain a "Subscription-State" header with a
                * value of "active", "pending", or "terminated". The "active" value
                * indicates that the subscription has been accepted and has been
                * authorized (in most cases; see section 5.2.). The "pending" value
                * indicates that the subscription has been received, but that
                * policy information is insufficient to accept or deny the
                * subscription at this time. The "terminated" value indicates that
                * the subscription is not active.
               Request notifyRequest = dialog.createRequest( "NOTIFY" );
               // Mark the contact header, to check that the remote contact is updated
               ((SipURI)contactHeader.getAddress().getURI()).setParameter("id","not");
               // Initial state is pending, second time we assume terminated (Expires==0)
               SubscriptionStateHeader sstate = headerFactory.createSubscriptionStateHeader(
                         isInitial ? SubscriptionStateHeader.PENDING : SubscriptionStateHeader.TERMINATED );
               // Need a reason for terminated
               if ( sstate.getState().equalsIgnoreCase("terminated") ) {
                    sstate.setReasonCode( "deactivated" );
               notifyRequest.addHeader(sstate);
               notifyRequest.setHeader(eventHeader);
               notifyRequest.setHeader(contactHeader);
               // notifyRequest.setHeader(routeHeader);
               ClientTransaction ct = udpProvider.getNewClientTransaction(notifyRequest);
               // Let the other side know that the tx is pending acceptance
               dialog.sendRequest(ct);
               System.out.println("NOTIFY Branch ID " +
                    ((ViaHeader)request.getHeader(ViaHeader.NAME)).getParameter("branch"));
               System.out.println("Dialog " + dialog);
               System.out.println("Dialog state after pending NOTIFY: " + dialog.getState());
               if (isInitial) {
                    Thread myEventSource = new Thread(new MyEventSource(this,eventHeader));
                    myEventSource.start();
          } catch (Throwable ex) {
               ex.printStackTrace();
               // System.exit(0);
     public synchronized void processResponse(ResponseEvent responseReceivedEvent) {
          Response response = (Response) responseReceivedEvent.getResponse();
          Transaction tid = responseReceivedEvent.getClientTransaction();
          if ( response.getStatusCode() !=  200 ) {
               this.notifyCount --;
          } else {
              System.out.println("Notify Count = " + this.notifyCount);
     public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
          Transaction transaction;
          if (timeoutEvent.isServerTransaction()) {
               transaction = timeoutEvent.getServerTransaction();
          } else {
               transaction = timeoutEvent.getClientTransaction();
          System.out.println("state = " + transaction.getState());
          System.out.println("dialog = " + transaction.getDialog());
          System.out.println("dialogState = "
                    + transaction.getDialog().getState());
          System.out.println("Transaction Time out");
    private static void initFactories ( int port ) throws Exception {
          SipFactory sipFactory = SipFactory.getInstance();
          sipFactory.setPathName("gov.nist");
          Properties properties = new Properties();
          properties.setProperty("javax.sip.STACK_NAME", "notifier" + port );
          // You need 16 for logging traces. 32 for debug + traces.
          // Your code will limp at 32 but it is best for debugging.
          properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
          properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
                    "notifierdebug_"+port+".txt");
          properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
                    "notifierlog_"+port+".txt");
          try {
               // Create SipStack object
               sipStack = sipFactory.createSipStack(properties);
               System.out.println("sipStack = " + sipStack);
          } catch (PeerUnavailableException e) {
               // could not find
               // gov.nist.jain.protocol.ip.sip.SipStackImpl
               // in the classpath
               e.printStackTrace();
               System.err.println(e.getMessage());
               if (e.getCause() != null)
                    e.getCause().printStackTrace();
               System.exit(0);
          try {
               headerFactory = sipFactory.createHeaderFactory();
               addressFactory = sipFactory.createAddressFactory();
               messageFactory = sipFactory.createMessageFactory();
          } catch  (Exception ex) {
               ex.printStackTrace();
               System.exit(0);
     public void createProvider() {
          try {
               ListeningPoint lp = sipStack.createListeningPoint(this.serverIP, this.port, "udp");
               this.udpProvider = sipStack.createSipProvider(lp);
               System.out.println("udp provider " + udpProvider);
          } catch (Exception ex) {
               System.out.println((ex.getMessage()));
               ex.printStackTrace();
               usage();
     public sipTrade( int port ) {
          this.port = port;
     public sipTrade(){
     public static void main(String args[]) throws Exception {
          int port = args.length > 0 ? Integer.parseInt(args[0]) : 5060;
          initFactories( port );
          sipTrade notifier = new sipTrade( port );
          notifier.createProvider( );
          notifier.udpProvider.addSipListener(notifier);
          //sipTrade st = new sipTrade();
          //st.Send2xTrade("198202050897", "testdata");
          //st.getXTmsg(0);
     public void processIOException(IOExceptionEvent exceptionEvent) {
     public void processTransactionTerminated(
               TransactionTerminatedEvent transactionTerminatedEvent) {
     public void processDialogTerminated(
               DialogTerminatedEvent dialogTerminatedEvent) {
          // TODO Auto-generated method stub
      * Xtrade connection - DATA IN
      public void Send2xTrade(String data, String info) {
           try{
                IServer is = ServerFactory.createObject(ip);
                is.logOn(clientName_in, SessionType.LogOnRxTx);
                is.sendMsg(contract_in,MsgPriority.Def, data.getBytes(), info);
                is.logOff();
           catch (Exception e){
                e.printStackTrace();
                System.err.println(e.getMessage());
      public void getXTmsg(int xtMsgAck){
          IMsg msg;               // A single xTrade message
          MsgInfo msgInfo = null;      // Message information
          byte[] theData;
          try {
               IServer is = ServerFactory.createObject(ip);
               is.logOn(clientName_out, SessionType.LogOnRxTx);
               msg = is.createNextRxMsg(contract_out);
               FileOutputStream myStream = new FileOutputStream("rx" + msg.getHandle() + ".msg");     // Create the stream                    
               msg.getData(myStream);
               myStream.close();
               if(msgInfo.getAcknowledge() == false){
                         msg.setReceived();
                    else if(msgInfo.getAcknowledge() == true && xtMsgAck == 0){
                          msg.setReceived();
                          msg.setAck();
                     else if(msgInfo.getAcknowledge() == true && xtMsgAck == 1){
                          msg.setReceived();
                          msg.setNack();
               is.logOff();
          }catch (XTException e){
          catch(Exception e){
}

Made som more fixes:
sipStack = gov.nist.javax.sip.SipStackImpl@e24e2a
sipStack = gov.nist.javax.sip.SipStackImpl@e24e2a
SipProviders: java.util.LinkedList$ListItr@1a73d3c
AddressFactory: class gov.nist.javax.sip.address.AddressFactoryImpl
InvalidArgumentException Cannot assign requested address: Cannot bindjavax.sip.InvalidArgumentException: Cannot assign requested address: Cannot bind
     at gov.nist.javax.sip.SipStackImpl.createListeningPoint(SipStackImpl.java:645)
     at sipClient.createProvider(sipClient.java:267)
     at sipClient.main(sipClient.java:302)
Caused by: java.io.IOException: Cannot assign requested address: Cannot bind
     at gov.nist.javax.sip.stack.UDPMessageProcessor.<init>(UDPMessageProcessor.java:135)
     at gov.nist.javax.sip.stack.SIPTransactionStack.createMessageProcessor(SIPTransactionStack.java:1652)
     at gov.nist.javax.sip.SipStackImpl.createListeningPoint(SipStackImpl.java:626)
     ... 2 more
Exception in thread "main" java.lang.NullPointerException
     at sipClient.main(sipClient.java:303)
import java.io.*;
import javax.sip.*;
import javax.sip.address.*;
import javax.sip.header.*;
import javax.sip.message.*;
import java.util.*;
public class sipClient implements SipListener {
     private static AddressFactory addressFactory;
     private static MessageFactory messageFactory;
     private static HeaderFactory headerFactory;
     private static Address address;
     private static SipStack sipStack;
     private int port;
     protected SipProvider udpProvider;
     protected Dialog dialog;
     protected int notifyCount = 0;
     public static final int PORT_5060 = 5070;     
     protected final String serverIP = "192.168.1.99";
     class MyEventSource implements Runnable {
          private sipClient st;
          private EventHeader eventHeader;
          public MyEventSource(sipClient notifier, EventHeader eventHeader ) {
               this.st = notifier;
               this.eventHeader = eventHeader;
          public void run() {
               try {
                    for (int i = 0; i < 100; i++) {
                         Thread.sleep(100);
                         Request request = this.st.dialog.createRequest(Request.NOTIFY);
                         SubscriptionStateHeader subscriptionState = headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
                         request.addHeader(subscriptionState);
                         request.addHeader(eventHeader);
                         // Lets mark our Contact
                         ((SipURI)dialog.getLocalParty().getURI()).setParameter("id","not2");
                         ClientTransaction ct = udpProvider.getNewClientTransaction(request);
                         System.out.println("NOTIFY Branch ID "+((ViaHeader)request.getHeader(ViaHeader.NAME)).getParameter("branch"));
                         this.st.dialog.sendRequest(ct);
                         System.out.println("Dialog " + dialog);
                         System.out.println("Dialog state after active NOTIFY: " + dialog.getState());
                         synchronized (sipClient.this) {
                         notifyCount ++;
               } catch (Throwable e) {
                    e.printStackTrace();
     private static void usage() {
          System.exit(0);
     public void processRequest(RequestEvent requestEvent) {
          Request request = requestEvent.getRequest();
          ServerTransaction serverTransactionId = requestEvent.getServerTransaction();
          System.out.println("\n\nRequest " + request.getMethod()+" received at " + sipStack.getStackName()+" with server transaction id " + serverTransactionId+" and dialog id "+requestEvent.getDialog());
          if (request.getMethod().equals(Request.SUBSCRIBE)) {
               processSubscribe(requestEvent, serverTransactionId);
      * Process the invite request.
     public void processSubscribe(RequestEvent requestEvent,
               ServerTransaction serverTransaction) {
          SipProvider sipProvider = (SipProvider) requestEvent.getSource();
          Request request = requestEvent.getRequest();
          try {
               System.out.println("notifier: got an Subscribe sending OK");
               System.out.println("notifier:  " + request);
               System.out.println("notifier : dialog = " + requestEvent.getDialog());
               EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
               if ( eventHeader == null) {
                    System.out.println("Cannot find event header.... dropping request.");
                    return;
               // Always create a ServerTransaction, best as early as possible in the code
               Response response = null;
               ServerTransaction st = requestEvent.getServerTransaction();               
               if (st == null) {
                    st = sipProvider.getNewServerTransaction(request);
               // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
               boolean isInitial = requestEvent.getDialog() == null;
               if ( isInitial ) {
                    // need random tags to test forking
                    String toTag = Integer.toHexString( (int) (Math.random() * Integer.MAX_VALUE) );
                    response = messageFactory.createResponse(202, request);
                    ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
                    // Sanity check: to header should not ahve a tag. Else the dialog
                    // should have matched
                    if (toHeader.getTag()!=null) {
                         System.err.println( "####ERROR: To-tag!=null but no dialog match! My dialog=" + dialog.getState() );
                    toHeader.setTag(toTag); // Application is supposed to set.
                    this.dialog = st.getDialog();
                    // subscribe dialogs do not terminate on bye.
                    this.dialog.terminateOnBye(false);
                    if (dialog != null) {
                         System.out.println("Dialog " + dialog);
                         System.out.println("Dialog state " + dialog.getState());
               } else {
                    response = messageFactory.createResponse(200, request);
               // Both 2xx response need a Contact
               address = addressFactory.createAddress("xTrade <sip:192.168.1.99>");
               ((SipURI)address.getURI()).setPort( udpProvider.getListeningPoint("udp").getPort() );                    
               ContactHeader contactHeader = headerFactory.createContactHeader(address);               
               response.addHeader(contactHeader);
               // Expires header is mandatory in 2xx responses to SUBSCRIBE
               ExpiresHeader expires = (ExpiresHeader) request.getHeader( ExpiresHeader.NAME );
               if (expires==null) {
                    expires = headerFactory.createExpiresHeader(30);     // rather short
               response.addHeader( expires );
               st.sendResponse(response);
                * NOTIFY requests MUST contain a "Subscription-State" header with a
                * value of "active", "pending", or "terminated". The "active" value
                * indicates that the subscription has been accepted and has been
                * authorized (in most cases; see section 5.2.). The "pending" value
                * indicates that the subscription has been received, but that
                * policy information is insufficient to accept or deny the
                * subscription at this time. The "terminated" value indicates that
                * the subscription is not active.
               Request notifyRequest = dialog.createRequest( "NOTIFY" );
               // Mark the contact header, to check that the remote contact is updated
               ((SipURI)contactHeader.getAddress().getURI()).setParameter("id","not");
               // Initial state is pending, second time we assume terminated (Expires==0)
               SubscriptionStateHeader sstate = headerFactory.createSubscriptionStateHeader(
                         isInitial ? SubscriptionStateHeader.PENDING : SubscriptionStateHeader.TERMINATED );
               // Need a reason for terminated
               if ( sstate.getState().equalsIgnoreCase("terminated") ) {
                    sstate.setReasonCode( "deactivated" );
               notifyRequest.addHeader(sstate);
               notifyRequest.setHeader(eventHeader);
               notifyRequest.setHeader(contactHeader);
               // notifyRequest.setHeader(routeHeader);
               ClientTransaction ct = udpProvider.getNewClientTransaction(notifyRequest);
               // Let the other side know that the tx is pending acceptance
               dialog.sendRequest(ct);
               System.out.println("NOTIFY Branch ID " +
                    ((ViaHeader)request.getHeader(ViaHeader.NAME)).getParameter("branch"));
               System.out.println("Dialog " + dialog);
               System.out.println("Dialog state after pending NOTIFY: " + dialog.getState());
               if (isInitial) {
                    Thread myEventSource = new Thread(new MyEventSource(this,eventHeader));
                    myEventSource.start();
          } catch (Throwable ex) {
               ex.printStackTrace();
               // System.exit(0);
     public synchronized void processResponse(ResponseEvent responseReceivedEvent) {
          Response response = (Response) responseReceivedEvent.getResponse();
          Transaction tid = responseReceivedEvent.getClientTransaction();
          if ( response.getStatusCode() !=  200 ) {
               this.notifyCount --;
          } else {
              System.out.println("Notify Count = " + this.notifyCount);
     public void processTimeout(javax.sip.TimeoutEvent timeoutEvent) {
          Transaction transaction;
          if (timeoutEvent.isServerTransaction()) {
               transaction = timeoutEvent.getServerTransaction();
          } else {
               transaction = timeoutEvent.getClientTransaction();
          System.out.println("state = " + transaction.getState());
          System.out.println("dialog = " + transaction.getDialog());
          System.out.println("dialogState = "
                    + transaction.getDialog().getState());
          System.out.println("Transaction Time out");
    private static void initFactories ( int port ) throws Exception {
          SipFactory sipFactory = SipFactory.getInstance();
          sipFactory.setPathName("gov.nist");
          Properties properties = new Properties();
          properties.setProperty("javax.sip.STACK_NAME", "notifier" + port );
          // You need 16 for logging traces. 32 for debug + traces.
          // Your code will limp at 32 but it is best for debugging.
          properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
          properties.setProperty("gov.nist.javax.sip.DEBUG_LOG","Xtradedebug_"+port+".txt");
          properties.setProperty("gov.nist.javax.sip.SERVER_LOG","Xtradelog_"+port+".txt");
          properties.setProperty("javax.sip.OUTBOUND_PROXY","192.168.1.99:5070/UDP");
          properties.setProperty("javax.sip.USE_ROUTER_FOR_ALL_URIS", "true");
          properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT","ON");
          try {
               // Create SipStack object
               sipStack = sipFactory.createSipStack(properties);
               System.out.println("sipStack = " + sipStack);
          } catch (PeerUnavailableException e) {
               // could not find
               // gov.nist.jain.protocol.ip.sip.SipStackImpl
               // in the classpath
               e.printStackTrace();
               System.err.println(e.getMessage());
               if (e.getCause() != null)
                    e.getCause().printStackTrace();
               System.exit(0);
          try {
               headerFactory = sipFactory.createHeaderFactory();
               addressFactory = sipFactory.createAddressFactory();
               messageFactory = sipFactory.createMessageFactory();
          } catch  (Exception ex) {
               ex.printStackTrace();
               System.exit(0);
     public void createProvider() {
          try {
               System.out.println("sipStack = " + sipStack);
               System.out.println("SipProviders: "+sipStack.getSipProviders().toString());
               System.out.println("AddressFactory: "+addressFactory.getClass());
               ListeningPoint lp = sipStack.createListeningPoint(this.serverIP, 5070, ListeningPoint.UDP);
               this.udpProvider = sipStack.createSipProvider(lp);
               System.out.println("udp provider " + udpProvider);
          }catch(SipException e){
               System.out.print("SipException "+e.getMessage());
               e.printStackTrace();
          /*catch(TransportNotSupportedException e){
               System.out.print("TransportNotSupportedException "+e.getMessage());
          catch (InvalidArgumentException e){
               System.out.print("InvalidArgumentException "+e.getMessage());
               e.printStackTrace();
          catch (Exception ex) {
               System.err.println((ex.getMessage()));
               ex.printStackTrace();
               usage();
     public sipClient( int port ) {
          this.port = port;
     public sipClient(){
     public static void main(String args[]) throws Exception {
          int port = args.length > 0 ? Integer.parseInt(args[0]) : 5070;
          initFactories( port );
          sipClient st = new sipClient( port );
          st.createProvider();
          st.udpProvider.addSipListener(st);
     public void processIOException(IOExceptionEvent exceptionEvent) {
     public void processTransactionTerminated(
               TransactionTerminatedEvent transactionTerminatedEvent) {
     public void processDialogTerminated(
               DialogTerminatedEvent dialogTerminatedEvent) {
          // TODO Auto-generated method stub
}

Similar Messages

  • Logical error in code, please help, thanks alot.

    I have this file Socks.java which reads in a file containing information about a sock drawer. The file is of the format:
    11
    red athletic
    green casual
    blue athletic
    blue athletic
    red athletic
    so when the program runs, it is supposed to output the socks that are pairs: so it would output
    1 pair red athletic
    1 pair blue athletic
    my code compiles and runs fine and i am testing it with println statements, but I am not getting the desired ouput. Can someone look over it and see if they spot what is wrong. Right now in the code I am seeing what the value of socks[i] and socks[j] is by printing them out as you will notice. If anyone can help, I appreciate it. Thanks so much for all your wonderful help
    Here is the code:
    import java.io.*;
    public class Socks {
    public static void main(String args[])
    try
    String socks[] = new String[1000];
    int pairs[] = new int[500];
    int numOfsocks;
    int i;
    int j;     
    FileReader fr = new FileReader("test.txt");
    BufferedReader inFile = new BufferedReader(fr);
    numOfsocks = Integer.parseInt(inFile.readLine());
    int possiblePairs = numOfsocks/2;
    //System.out.println(numOfsocks);
    //System.out.println(possiblePairs);
    for(i = 0; i < numOfsocks; i++)
    socks[i] = inFile.readLine();
    //for(i = 0; i < numOfsocks; i++)
    //System.out.println(socks);
    for(i = 0; i <= possiblePairs;i++)
    for(j = i; j <= possiblePairs;j++)
    System.out.println(socks[i]);
    System.out.println(socks[j]);
    //if(pairs[i] >= 2)
    //System.out.println(pairs[i]/2 + " pairs" + socks[i]);
    inFile.close();     
    catch(IOException e){}
              System.out.println("File Not Found or no File Specified");

    Try the following quickly revised version of your code.
    import java.io.*;
    public class Socks {
    public static void main(String args[])
      try
        String socks[] = new String[1000];
        int pairs[] = new int[500];
        int numOfsocks;
        int i;
        int j;
        FileReader fr = new FileReader("test.txt");
        BufferedReader inFile = new BufferedReader(fr);
        numOfsocks = Integer.parseInt(inFile.readLine());
        for(i = 0; i < numOfsocks; i++)
          socks[i] = inFile.readLine();
        for(i = 0; i < numOfsocks; i++)
          if (socks[i] != null)
            pairs[i]++;
            for(j = i + 1; j < numOfsocks; j++)
                if (socks.equals(socks[j]))
    pairs[i]++;
    socks[j] = null;
    System.out.println(pairs[i]/2 + " pairs " + socks[i]);
    inFile.close();
    catch(IOException e){
    e.printStackTrace();

  • Errors in code, please help

    I am trying to generate random motion in flash and can't seem
    to make it work.
    Any help will be much appreciated
    newpos = function () {
    ranx = Math.random ()*250)
    rany = Math.random ()*250)
    this.onEnterFrame = function() {
    newpos ()
    this._x = ranx;
    this._y = rany;
    acceleration = 10
    newpos = function () {
    ranx = Math.round((Math.random ()*250));
    rany = Math.round ((Math.random ()*250));
    newpos();
    this.onEnterFrame = function() {
    this._x += ((ranx-this._x)/ acceleration);
    this._y += ((rany-this._y)/ acceleration);
    acceleration = 10
    newpos = function () {
    ranx = Math.round((Math.random ()*250));
    rany = Math.round ((Math.random ()*250));
    newpos();
    this.onEnterFrame = function() {
    this._x += ((ranx-this._x)/acceleration);
    this._y += ((rany-this._y)/acceleration);
    if (Math.round(this._x) == ranx || Math.round(this._y) ==
    rany) {
    newpos();

    Try this:
    newpos = function () {
    acceleration = 10;
    ranx = Math.round((Math.random()*250));
    rany = Math.round((Math.random()*250));
    this._x += ((ranx-this._x)/acceleration);
    this._y += ((rany-this._y)/acceleration);
    this.onEnterFrame = function() {
    newpos();
    cheers,
    blemmo

  • My dear during i update my iphone 4s 16 giga  to ios 7 itis not responde and error 4005  wasfound please help me

    dear sir during updating my iphone 4s 16 giga error 4005 found please help me

    http://lmgtfy.com/?q=iPhone+error+code+4005

  • Error 213.5 Please help me get DW working again. Thanks CaptJim4685

    I have a Mac OS 10.10 used the Migration Assistant to move all files from old computer to new computer yesterday. Now can not use my Dreamweaver CS 5.5 program I have my original install disk. Tried that. get error 213.5 Please help me get DW working again. Thanks CaptJim4685

    Hi Nancy O.
    Thing is, I was using it on my old MacBookPro, also w/ yosemite. No problem. So I think it should run on the new one with the same OS.
    I did figure out how to find the CC cleaner log file. It had a lot of stuff in it, but did not indicate any kind of failures. I did not see the word “failure in the log file at all.
    After your suggestions, I went thru all the steps again - twice - very carefully emptying the trash between steps and restarting. Got the same error message at the end.
    Now, I still have 5.5 working on the old computer. That was my first and only install. My notes suggest  I installed it in 2011.
    If I knew for sure that if I deactivated it (if I knew how to do that) on the old computer, and uninstalled it, AND I could then count on the install working on my new computer, I would do it, but I am afraid to do that for fear that then I wouldn’t have it to use at all.
    I had expected it to transfer over, and then I would clean the old computer, as my son wants it for his wife, They have no use for DW.
    I also had trouble w/ MS Office, but they allowed me to call them and get a new install code. Now that Works fine.
    I wish Adobe were as accommodating. I have my original install disk & code. I never expected any of this trouble.
    I hope you can come up with a new plan. I really can’t afford to buy a new copy, especially when I know that this one should work, if it would just get rid of this blocking action.
    I only use it for editing my own personal family website: http:www.americanfenner.com.  I am not a webmaster/webwriter/ computer programmer or anything like that. Just an old guy doing personal stuff on my mac.
    Jim Fenner
    [email protected]

  • TS3694 How can I fix this type of error in iphone 4?"The iphone could not be restored. An unknown error occurred (3194) "please help me.

    Hi everybody !
    AT&T company is unlocked (factory)my iphone4 before 3 days ago so i want to restore to unlock iphone 4 with itunes but it is not restore.
    How can I fix this type of error in iphone 4?- "The iphone could not be restored. An unknown error occurred (3194) "
    please help me in nepali language(if posible) or english. thank you.

    http://support.apple.com/kb/TS3694#error3194
    This means that either your firewall/antivirus is blocking access to Apple's servers, or you have used your computer to jailbreak an iDevice in the past. The link above tells you how to resolve this issue.

  • I have a compilation problem with my mini iPod that is preventing my volume from increasing. I can't get the compilation code, please help me

    MY mini iPod version number1.1.3 pc robs iPod ,4GB is having volume limit problem ,the volume is very low compare to how it was playing before I mistakenly touch the combination code. I have forgotten the combination code, please help me out.. I have tried to reset settings but it wouldn't work.

    i can get the combination code please

  • TS2865 when i export movie from final cut pro to quicktime , something happened. it says error quicktime -50. please help.

    when i export movie from final cut pro to quicktime , something happened. it says error quicktime -50. please help.
    i need to submit this movie for uni project tomorrow.
    any help/advice will help . thanks.

    According to Crash Analyzer
    -50 (QuickTime)
    This error occurs when there is corrupt or invalid media in your timeline. Check that the codec used by the file is recommended for use in your editing application.
    good luck

  • TS3694 hi, I was trying to update my iPhone 3gS but when I turn it on again iTunes send me a message that says error 3194 occurs, please help me!!

    hi, I was trying to update my iPhone 3gS but when I turn it on again iTunes send me a message that says error 3194 occurs, please help me!!

    If the screen shows a plug going to itunes, then you have no choice,  It's in recovery mode.  You'll be given the chance to restore from a backup either from itunes or icloud.
    I assume when you got the message to update (was this for the ios or update some apps?), that was before the device when dead.  At any rate, doing a restore does not change the ios.

  • HT201413 Whenever i try to sync my ipod a message keeps coming up saying "1 or more items could not be synced", apparently its error -69. Please help, i've tried rebooting my laptop, installing the latest itunes and turning off the wifi but nothing seems

    Whenever i try to sync my ipod a message keeps coming up saying "1 or more items could not be synced", apparently its error -69. Please help, i've tried rebooting my laptop, installing the latest itunes and turning off the wifi but nothing seems to work.

    Are you using security software on your PC? If yes, try to disable the software or check the settings. More info here: http://support.apple.com/kb/TS3125

  • My ipad mini 2 is not turning on. I tried to reset with the power/home buttons but it didnt work. I tried to restore it in DFU mode but it didnt work, i get error 4004. Please help me!

    My ipad mini 2 is not turning on. I tried to reset with the power/home buttons but it didnt work. I tried to restore it in DFU mode but it didnt work, i get error 4004. Please help me!

    I also tried the ol' whacking 3 times trick...Didn't work to my surprise

  • I backed up my movies and rebuild my computer, and after making sure i'm using the latest version of itunes and quicktime and and making sure i still had spare computer authorizations, i still get error 23132.  Please help.

    I backed up my movies and rebuild my computer, and after making sure i'm using the latest version of itunes and quicktime and and making sure i still had spare computer authorizations, i still get error 23132.  Please help.

    I had this exact issue.  Spent over an hour on the phone with apple support, they couldn't resolve.  Here is what I ended up doing, that worked.
    1.  Turned iTunes match off on all my iOS devices
    2.  Deleted the offending playlists from the iOS device they originated on
    3.  Started iTunes, let it run (literally) for an hour before it became responsive.  First thing I did, before clicking anywere else was disable iTunes match.  If I clicked anywhere, it would clock for another hour.
    4.  Let iTunes run overnight, by morning it had cleaned out the repeating play lists.  This got my Mac/iTunes back to an operable state.
    5.  Restore iPhones from backup in iTunes.
    What was causing my issue was a single playlist that was created on an iPhone, then suddenly showed up with several thousand duplicates on my other iPhone.  The culprit playlist did not, for some reason, duplicate itself on my two iPads.  Apple support seemed to think it was because the problem iPhone tried to sync the playlist to iCloud over and over again unsuccessfully, then it finally went through and populated the thousands of blank/failed playlists which then tried to propigate to iTunes and my other iOS devices.  Seems like a reasonable theory.
    I have not yet re-enabled iTunes match.  So, no idea what will happen if I decide to go back down that rabbit hole.

  • ýesterday  my iphone 5c screen  suddendly  shows connect to itune and i try to restore it using itune but halfway i got a message error occured (14). please help me in solving this problem.

    ýesterday  my iphone 5c screen  suddendly  shows connect to itune and i try to restore it using itune but halfway i got a message error occured (14). please help me in solving this problem.

    what did you learn when you search the internet for iPhone error 14?

  • I am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.

    i am not able to sync some videos and apps onto my iphone 3gs. it shows a sync error: 0xe8008001.i updated it but still i am getting the same sync error problem..please help.
    aman

    Are you using Windows...?

  • TS3694 Hello. I have an iphone 3gs 8gb factory unlocked. Currently its running on ios 5.0.1 and I am trying to update it ios 5.1.1 but its not updating. The itunes downloads the ios 5.1.1and gives back unknown error(3194). Please help.

    Hello. I have an iphone 3gs 8gb factory unlocked. Currently its running on ios 5.0.1 and I am trying to update it ios 5.1.1 but its not updating. The itunes downloads the ios 5.1.1and gives back unknown error(3194). Please help.

    Unable to contact the iOS software update server gs.apple.com
    Error 1004, 1013, 1638, 3194: These errors may be the result of the connection to gs.apple.com being redirected or blocked. Follow these steps to resolve these errors:
    Install the latest version of iTunes.
    Check security software. Ensure that communication to gs.apple.com is allowed. Follow this article for assistance with security software. iTunes for Windows: Troubleshooting security software issues.
    Check the hosts file. The restore will fail if there is an active entry to redirect gs.apple.com. FollowiTunes: Advanced iTunes Store troubleshooting to edit the hosts file or revert to a default hosts file. See section "Blocked by configuration: (Mac OS X/Windows) > Rebuild network information".
    Try to restore from another known-good computer and network.
    If the errors persist on another computer, the device may need service.

  • My macbook is blocked by pin code, please help, I dont know what to do!

    My macbook is blocked by pin code, please help, I dont know what to do!

    When you enter iTunes on the PC and the iPod icon pops up, right click on it and select "Options". Then click on the Music tab. Once you're in the Music tab check the box that says "Enable Disc Use". This means that you've just turned your iPod into a portable hard drive. Click "Ok" and move your iPod from the PC to the Mac. From there, your iPod should show up on the Mac's desktop right under the Hard Drive icon. Click "File" at the top of the screen and select "Add to Library". Find the iPod hard drive in the selection screen and choose the music folder that's on it. Then just click Ok and all your music will be downloaded. That should do the trick, but you might want to do a Google search on the subject to get a second opinion. Best wishes!

Maybe you are looking for