Skip to main content

HELP on compiler error!!!!

1 reply [Last post]
Joined: 2006-02-17

I am trying to run this program, but it keeps giving me this error, please hELP!!!!!!!!!!!!

C:\jcommapi\commapi\samples\ ';' expected
byte[] charArrayToByteArray(char line[], int offset, int len)
1 error

import javax.comm.*;
import java.util.*;
import java.lang.Object;

public class PortTyper{
static String x= "COM1";
public static void main (String [] args){

try {
CommPortIdentifier com = CommPortIdentifier.getPortIdentifier(x);
CommPort thePort ="PortOpener", 10);
copyThread input = new copyThread(thePort.getOutputStream());
copyThread output = new copyThread(thePort.getInputStream());
}//end try
catch (Exception e) {System.out.println(e);}
}//end class PortTyper

class copyThread extends Thread {
InputStream theInput;
OutputStream theOutput;

copyThread(InputStream in){

theInput = in;

copyThread(OutputStream out){

theOutput = out;

public void run(){

try {
byte[]buffer = new byte[256];
char[]line = {'h', 'e', 'l', 'p', '\13'};
buffer = charArrayToByteArray(line,0,6);

byte[] charArrayToByteArray(char line[], int offset, int len)
CharBuffer charBuf = charBuf.wrap(chars,offset,len);
return charSetEncoder.encode(charBuf).array();

while (true){

int bytesRead =;
if (bytesRead == -1)break;

theOutput.write(buffer, 0,bytesRead);


catch (IOException e) {System.err.println(e);}


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-02-17

You've tried to define the method charArrayToByteArray( ) in the middle of method run( ). Try moving the method definition outside of run( ).