i am trying to send AT commands on a GSM modem.
this is my code..

import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite 
{
	static Enumeration portList;
	static CommPortIdentifier portId;
	static String commands[] ={"AT+CMGS=1","AT+CMGS=\"+919007413343\","Hello there"};
	static byte[] newline[]={(byte)13,(byte)10};
	static SerialPort serialPort;
	static OutputStream outputStream;
public static void main(String[] args) 
{
	portList = CommPortIdentifier.getPortIdentifiers();
	while (portList.hasMoreElements()) 
	{
	portId = (CommPortIdentifier) portList.nextElement();
		if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)

		{
			if (portId.getName().equals("COM13")) //your comm port
			{
				try 
				{
				serialPort = (SerialPort)
				portId.open("SimpleWriteApp", 2000);
				} 	
				catch (PortInUseException e) {}

				try 
				{
					//get the output stream
					outputStream = serialPort.getOutputStream();
					//write the commands string to the output stream
					for(int i=0;i<commands.length;i++)
					{ 
						outputstream.write(commands[i]); // write command
						outputstream.write(newline); //write new line
					}
					outputStream.write(messageString.getBytes());
				} 
				catch (IOException e) {}
			}
		}
	}
}
}

while compiling i am getting following error..

SimpleWrite.java:8: '}' expected
        static String commands[] ={"AT+CMGS=1","AT+CMGS=\"+919007413343\","Hello
 there"};
                                                                           ^
SimpleWrite.java:8: unclosed string literal
        static String commands[] ={"AT+CMGS=1","AT+CMGS=\"+919007413343\","Hello
 there"};

      ^
2 errors

please help...

i am trying to send sms.....

Count and match your quotes - there are 7 on that line = 1 unmatched. The colour coding (blue = string literal) in your posted code is a good clue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.