could any one help me to update this code to be able to send image from computer to mobile
i have updated the method save() in the server code
the method updated is

public void save(){
try{
ImageIO.write(img, "jpg", new File("dynamics.jpg"));
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
wr.write("image_sending");
wr.flush();}
catch(IOException ioe){
System.err.println("write: " + ioe.getMessage());}
}

but it give me error
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));


server code


package serverproject;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main extends Component {
public static int[] x=new int[30] ;
public static int[] y=new int[30];
public static int i;
public static int ij=0;
public static int[] d=new int[30];
public static int c = 0;
public static int[] s=new int[30];
public static int[] prev=new int[30];
public static int[] q=new int[30];
public static int[][] A=new int[300][300] ;
public static int[] sx=new int[30] ;
public static int[] sy=new int[30] ;
public static Graphics g;
public static int start;
private static Socket toClient;
private static BufferedReader in;
private static InputStream input;
private static OutputStream output; public static int w=0;
Socket socket;
boolean work = true;
public static int startx;
public static int starty;
public static void main(String args[]) {
try {
System.out.println("S: Connecting...");
ServerSocket serverSocket = new ServerSocket(12344);
toClient = serverSocket.accept();
System.out.println("S: Connected");
output = toClient.getOutputStream();
Thread desktopServerThread = new Thread(){
public void run(){
while(true){
try {
in= new BufferedReader(new InputStreamReader(toClient.getInputStream()));
String str;
if (!(str=in.readLine()).equals("") | !str.equals(" "))
System.out.println("C: '" + str);
int b = str.indexOf('d');
String startpt = str.substring(1, b);
int bbb=startpt.indexOf(',');
String bx = startpt.substring(0, bbb);
String by = startpt.substring(bbb+1);
startx=Float.valueOf(bx.trim()).intValue();
starty=Float.valueOf(by.trim()).intValue();
String destpt = str.substring(b+1);
System.out.println("sending " + str + " ) to Mobile");
output.write(str.getBytes());
System.out.println("Sending Message Succesful"+" s "+startpt+" d "+destpt);
System.out.println("xx "+startx+" yy "+starty);
w=1;
if (w==1){
JFrame frame = new JFrame("Image Label");
BufferedImage img = null;
Main tt = new Main(img,"");
tt.dbTest();
String imageFileName = "map.png";
img = ImageIO.read(new File(imageFileName));
frame.add("Center", new Main(img, ""));
frame.pack();
frame.setVisible(true);
}
} catch(Exception e) {
e.printStackTrace();
break;
}
}
}
};
desktopServerThread.start();

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

}

BufferedImage img;
String text;
Font font;
public Main(BufferedImage img, String text) {
this.img = img;
this.text = text;
font = new Font("Serif", Font.PLAIN, 36);
}

public Dimension getPreferredSize() {
FontMetrics metrics = img.getGraphics().getFontMetrics(font);
int width = metrics.stringWidth(text) * 2;
int height = metrics.getHeight() * 2;
return new Dimension(width, height);
}
public void paint(Graphics g) {

g=img.getGraphics();
int[] x= Main.x;
int[][] A=Main.A;
Dimension size = getSize();
g.drawImage(img, 0, 0, 800, 600, this);

g.setColor(Color.BLACK);
g.setFont(font);
FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(text, frc);

for(int j = 0; j <i; j++) {
g.fillRect(x[j] ,y[j], 15, 15);
d[j]=1000;

}
int c=start;
int dest=10;
d[c]=0;
int m=-1;
q[c]= -1;
while (q[i-1]!=-1)
{
if (c==dest){
break;
}
int minvalue=1000;
for (int jj=0;jj<i;jj++){

if(jj!=c & A[c][jj]!=0 & A[c][jj]!=1000 & q[jj]!=-1){

int alt=d[c]+A[c][jj];
if (alt <= d[jj]){
d[jj]=alt;
prev[jj]=c;
}
if (d[jj]<minvalue){m=jj;
minvalue=d[jj];

}
}
}
if (m==c){q[start]=0;}
if (m!=-1 & m!=c){
c=m;

}

q[c]= -1;

}
s[ij]=dest;
c=dest;
ij=0;

while (s[ij]!=start){

ij=ij+1;
s[ij]=prev[c];
c=prev[c];


}
for (int ik=0;ik<=ij;ik++){

sx[ik]=x[s[ik]];
sy[ik]=y[s[ik]];
}

g.drawPolyline(sx, sy, ij+1);

save();
}


void dbTest() {
DataInputStream dis = null;
String dbRecord = null;
DataInputStream diss = null;
String dbRecordd = null;
try {

File f = new File("waypoints.txt");
File ff = new File("data.txt");
FileInputStream fis = new FileInputStream(f);
FileInputStream fiss = new FileInputStream(ff);
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedInputStream biss = new BufferedInputStream(fiss);
dis = new DataInputStream(bis);
diss = new DataInputStream(biss);
i=0;


while ( (dbRecord = dis.readLine()) != null) {

StringTokenizer st = new StringTokenizer(dbRecord );//":");
String xxx = st.nextToken();
String yyy = st.nextToken();



int xx = Integer.parseInt(xxx.trim());
int yy = Integer.parseInt(yyy);


x[i] = xx;
y[i]=yy;

if (startx==(xx/10) & starty==(yy/10) ){start=i;
}
i=i+1;
}

int l=0;
while ( (dbRecordd = diss.readLine()) != null) {
int k=0;
StringTokenizer stt = new StringTokenizer(dbRecordd );//":");
while(stt.hasMoreTokens()){

A[l][k] = Integer.parseInt(stt.nextToken());

k=k+1;
}
l=l+1;
}

} catch (IOException e) {

} finally {
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
}

}
}

}
public void save()

{

try

{


ImageIO.write(img, "jpg", new File("dynamics.jpg"));

}

catch(IOException ioe)

{

System.err.println("write: " + ioe.getMessage());

}

}

}

client code

package routing;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
import java.io.*;
import javax.microedition.io.*;
public class route extends MIDlet implements CommandListener,LocationListener {
private boolean midletPaused = false;
private Command exitCommand;
private Command okCommand;
private Command okCommand1;
private Form form;
private TextField textField1;
private TextField textField;
private Display display;
public LocationProvider provider;
public Location location;
public QualifiedCoordinates qc;
public String startpt;
InputStream is;
OutputStream os;

public route() {
display = Display.getDisplay(this);

try{
provider = LocationProvider.getInstance(null);
provider.setLocationListener(this, -1, 0, 0);


}
catch ( LocationException e ) { textField1.setString(e.getMessage()); }
}

public void sendMessage(String message) throws IOException {
message = prepare(message);
byte[] data = message.getBytes();

os.write(data);
os.flush();
System.out.println("message has been sent: " + new String(data));

}

public String recieveMessage() throws IOException {


StringBuffer sb = new StringBuffer();
int c = 0;
while (((c = is.read()) != '\n') && (c != -1)) {
sb.append((char) c);
}
System.out.println("recieved from server: " + sb.toString());
return sb.toString();
}
public void sendMessageToServerAndReadResponse() {
try {
sendMessage( "s"+startpt+"d"+textField.getString());
recieveMessage();
} catch (IOException ex) {

return;
}


}
public void startMIDlet() {
PrintStream r = System.out;
r.println("BEFORE TRY");
try {
SocketConnection sc = (SocketConnection) Connector.open("socket://localhost:12344");
System.out.println("connection is open...");
os = sc.openOutputStream();

is = sc.openInputStream();


} catch (IOException x) {
x.printStackTrace();
}
public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
if (displayable == form) {
if (command == exitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
} else if (command == okCommand) {
// write pre-action user code here

sendMessageToServerAndReadResponse();
}
}
}

public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}
String prepare(String message) {
String r = message;
r = r + "\n";
return r;
}

public void startApp() {
textField1 = new TextField("GPS", "Searching..", 256, 0);

if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
textField1.addCommand(exitCommand);
public void pauseApp() {
midletPaused = true;
}

public void destroyApp(boolean unconditional) {
}

public void locationUpdated(final LocationProvider prov, final Location loc) {
new Thread() {

public void run() {
if (loc != null && loc.isValid()) {
qc = loc.getQualifiedCoordinates();
if(qc.getLongitude()!=0)
{
try{
sleep(5);
}catch(Exception e){}
}

String coord="Lat:"+qc.getLatitude()+"° Lon:"+qc.getLongitude() +"°";
startpt=qc.getLatitude()+","+qc.getLongitude();
textField1.setString(coord);
}
else {
textField1.setString("Location null or invalid object:\n");
}
}
}.start();
}
public void providerStateChanged(LocationProvider arg0, int arg1) {
throw new UnsupportedOperationException("Not supported yet.");
}

}