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: Please help. Whats wrong with this code

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Please help. Whats wrong with this code

    I want to make project about java communication with hardware (wiz110sr) via LAN (Rj45). And for example, my hardware have ip address 198.168.0.1 ; port: 1202, connected with my PC(via lan/Rj45). I want show the output (such as numbers and letters) from my hardware in console netbeans.
    When I running my code, appear :
    " Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code
    at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48)
    at java.lang.Thread.run(Thread.java:745)
    BUILD SUCCESSFUL (total time: 1 second) "


    Here's the code :

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.InetAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import sun.rmi.runtime.Log;
     
    /**
     *
     * @author Owner
     */
    public class startListenForTCP {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException {
     
        Thread TCPListenerThread = new Thread(new Runnable() {
            @Override
            public void run() {
     
                Boolean run = true;
                String serverMessage = null;
                InetAddress serverAddr = null;
     
                try {
                    Socket clientSocket = new Socket("198.168.0.1", 1202);
     
                    try
    {
        char[] buffer = new char[2048];
        int charsRead = 0;
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        while ((charsRead = in.read(buffer)) != -1)
        {
            String message = new String(buffer).substring(0, charsRead);
            Log.e("In While", "msg :"+message);
     
        }
     
                    } catch(UnknownHostException e) {
                        mHandler.post(new DisplayToast(context, "UnknownHostException"));
     
                    } catch(IOException e) {
                        mHandler.post(new DisplayToast(context, "IOException"));
                    } finally {
                        clientSocket.close();
                    }
     
                } catch (IOException e) {
                    e.printStackTrace();
                }
     
            }
        });
            TCPListenerThread.start();
        }
    }

    Please help me


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,817
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Please help. Whats wrong with this code

    Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code
    at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48)
    What code is at line 48?
    Can you use a javac compiler to get a compiler error message that will say what the problem is?
    Does your IDE indicate an error for that line? What does it say?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help. Whats wrong with this code

    Here's the code at line 48 :
    Log.e("In While", "msg :"+message);

    Please help me

    --- Update ---

    Here's the code at line 48 :
    Log.e("In While", "msg :"+message);

    Please help me

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,817
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Please help. Whats wrong with this code

    What is the error message for that line? Why does the compiler think there is a problem there?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help. Whats wrong with this code

    I don't know too. Do you think my code is correct? Or is there something wrong with my code? If there is something wrong with my code, please help me to fix it.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,817
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Please help. Whats wrong with this code

    You need to copy the full text of the compiler's error messages and paste it here so we know what the problem is.

    If you can not get a good error message from your IDE, open a command prompt window and use the JDK's javac command. It gives good error messages.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Please help. Whats wrong with this code


  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,817
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Please help. Whats wrong with this code

    I can't read those images. Can you copy the messages and post them?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Nov 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help. Whats wrong with this code

    Here's the code:
    package mypkg;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.InetAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import sun.rmi.runtime.Log;

    /**
    *
    * @author Owner
    */
    public class startListenForTCP {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws IOException {

    Thread TCPListenerThread = new Thread(new Runnable() {
    @Override
    public void run() {

    Boolean run = true;
    String serverMessage = null;
    InetAddress serverAddr = null;

    try {
    //serverAddr = InetAddress.getByName("192.168.11.254");
    //Socket clientSocket = new Socket(serverAddr, 5566);
    Socket clientSocket = new Socket("192.168.11.2", 5000);

    try
    {
    char[] buffer = new char[2048];
    int charsRead = 0;
    BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    while ((charsRead = in.read(buffer)) != -1)
    {
    String message = new String(buffer).substring(0, charsRead);
    Log.e("In While", "msg :"+message); //Here's the code at line 48

    }

    } catch(UnknownHostException e) {
    mHandler.post(new DisplayToast(context, "UnknownHostException"));

    } catch(IOException e) {
    mHandler.post(new DisplayToast(context, "IOException"));
    } finally {
    clientSocket.close();
    }

    } catch (IOException e) {
    e.printStackTrace();
    }

    }
    });
    TCPListenerThread.start();
    }
    }



    Here's error message:

    Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code
    at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48)
    at java.lang.Thread.run(Thread.java:745)
    BUILD SUCCESSFUL (total time: 1 second)

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,817
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Please help. Whats wrong with this code

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Can you post the full text of the compiler's error message that says what the problem is with line 48?

    Uncompilable source code
    What you have posted does not describe the problem.

    Here's a sample of the error message from the javac compiler:
    The message should show the source with a ^ under the location of the error.
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Nov 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help. Whats wrong with this code

    D:\Documents and Settings\Owner>javac 1.java
    1.java:15: class startListenForTCP is public, should be declared in a file named
     startListenForTCP.java
    public class startListenForTCP {
           ^
    1.java:26: incompatible types
    found   : boolean
    required: java.lang.Boolean
                Boolean run = true;
                              ^
    1.java:43: cannot resolve symbol
    symbol  : method e (java.lang.String,java.lang.String)
    location: class sun.rmi.runtime.Log
                                                            Log.e("In While", "msg :
    "+message);
                                                               ^
    1.java:47: cannot resolve symbol
    symbol: class DisplayToast
                                                    mHandler.post(new DisplayToast(c
    ontext, "UnknownHostException"));
                                                                      ^
    1.java:47: cannot resolve symbol
    symbol: variable context
                                                    mHandler.post(new DisplayToast(c
    ontext, "UnknownHostException"));
                                                                                   ^
     
    1.java:47: cannot resolve symbol
    symbol: variable mHandler
                                                    mHandler.post(new DisplayToast(c
    ontext, "UnknownHostException"));
                                                    ^
    1.java:49: cannot resolve symbol
    symbol: class DisplayToast
                                                    mHandler.post(new DisplayToast(c
    ontext, "IOException"));
                                                                      ^
    1.java:49: cannot resolve symbol
    symbol: variable context
                                                    mHandler.post(new DisplayToast(c
    ontext, "IOException"));
                                                                                   ^
     
    1.java:49: cannot resolve symbol
    symbol: variable mHandler
                                                    mHandler.post(new DisplayToast(c
    ontext, "IOException"));
                                                    ^
    9 errors


    --- Update ---

    Norm : Do you have any idea for make this project?

  12. #12
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,070
    My Mood
    Mellow
    Thanks
    243
    Thanked 752 Times in 738 Posts

    Default Re: Please help. Whats wrong with this code

    Please post your code correctly.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,817
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Please help. Whats wrong with this code

    Where did you copy this code from? It looks like you did not copy all the parts needed.

    First error: class startListenForTCP is public, should be declared in a file named startListenForTCP.java
    The source file name is wrong. It should make the class name.

    2nd error:
    1.java:26: incompatible types
    found : boolean
    required: java.lang.Boolean
    Boolean run = true;
    true is not a Boolean, it is a boolean. Change one of them so they match: boolean or Boolean.TRUE

    3rd error: cannot resolve symbol
    The compiler can not find a definition for the symbol named in the error message.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Help me on this code whats wrong with it?
    By Shoes Mosh in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 2nd, 2014, 10:16 AM
  2. [SOLVED] Whats wrong with my code
    By ansiaries in forum Loops & Control Statements
    Replies: 2
    Last Post: March 27th, 2014, 01:16 PM
  3. whats wrong with my code
    By abhi1402 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 6th, 2013, 09:17 AM
  4. hi if u can help me please whats wrong with this code
    By ohad in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 8th, 2013, 03:04 PM
  5. Whats Wrong with this code?
    By whattheeff in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2011, 10:59 PM