السلام عليكــم ورحمـة الله وبركاتــه
كنت عملت برنامج PhoneBook علي نظام client server ولكن واجهتني مشكله
وهي عندما يقوم client بادخال البيانات لكي يرسلها لي server يطلع الي رساله Exception وهي
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "alaa"
البيانات الي دخلتها كانت من ضمنها الاسم alaa لا ادري ما المشكله ..
هاي هي الكلاسات ..
PhoneBook.java
* @(#)PhoneBook.java
*
*
* @author
* @version 1.00 2009/9/3
*/
public class PhoneBook
{
private int Id;
private String name;
private int mobile;
private int phone;
private String Address;
public PhoneBook(int Id,String name,int mobile,int phone,String Address)
{
this.Id = Id;
this.name = name;
this.mobile = mobile;
this.phone = phone;
this.Address = Address;
}
public int getId()
{
return Id;
}
public String getName()
{
return name;
}
public int getPhone()
{
return phone;
}
public int getMobile()
{
return mobile;
}
public String getAddress()
{
return Address;
}
}
/**
PhoneServer.java
* @(#)PhoneServer.java
*
*
* @author
* @version 1.00 2009/9/4
*/
import java.net.*;
import java.io.*;
public class PhoneServer
{
private static ObjectOutputStream output;
private static ObjectInputStream input;
private static Socket socket;
public static void main(String arge[])
{
try
{
System.out.println(" **** Start Phone Server **** ");
ServerSocket serverSocket = new ServerSocket(8000);
output = new ObjectOutputStream(new FileOutputStream("Phone.txt",true));
while(true)
{
socket = serverSocket.accept();
input = new ObjectInputStream(socket.getInputStream());
Object object = input.readObject();
output.writeObject(object);
}
}
catch(IOException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
finally
{
try
{
input.close();
output.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
}
}
/**
PhoneClient.java
* @(#)PhoneClient.java
*
*
* @author
* @version 1.00 2009/9/3
*/
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class PhoneClient extends JFrame implements ActionListener
{
private JTextField name = new JTextField(32);
private JTextField phone = new JTextField(32);
private JTextField address = new JTextField(20);
private JTextField ID = new JTextField(2);
private JTextField Mobile = new JTextField(8);
private JButton register = new JButton("Register To The Server");
public PhoneClient()
{
super("PhoneBook Client");
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch (Exception ex)
{
ex.printStackTrace();
}
Container c = getContentPane();
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3,1));
p1.add(new JLabel(" Name "));
p1.add(new JLabel(" Phone "));
p1.add(new JLabel(" Address "));
JPanel id = new JPanel();
id.setLayout(new BorderLayout());
id.add(new JLabel(" Id "),BorderLayout.WEST);
id.add(ID,BorderLayout.CENTER);
JPanel mobile = new JPanel();
mobile.setLayout(new BorderLayout());
mobile.add(new JLabel(" Mobile "),BorderLayout.WEST);
mobile.add(Mobile,BorderLayout.CENTER);
JPanel p2 = new JPanel();
p2.setLayout(new BorderLayout());
p2.add(id ,BorderLayout.WEST);
p2.add(mobile,BorderLayout.CENTER);
JPanel p3 = new JPanel();
p3.setLayout(new BorderLayout());
p3.add(address,BorderLayout.CENTER);
p3.add(p2,BorderLayout.EAST);
JPanel p4 = new JPanel();
p4.setLayout(new GridLayout(3,1));
p4.add(phone);
p4.add(name);
p4.add(p3);
JPanel Phone = new JPanel(new BorderLayout());
//Phone.setBorder(new BevelBorder(BevelBorder.RAISED));
Phone.add(p1,BorderLayout.WEST);
Phone.add(p4,BorderLayout.CENTER);
register.addActionListener(this);
c.add(Phone,BorderLayout.CENTER);
c.add(register,BorderLayout.SOUTH);
setSize(350,130);
setVisible(true);
}
public static void main(String arge[])
{
new PhoneClient();
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() == "Register To The Server")
{
try
{
InetAddress addressIP = InetAddress.getLocalHost();
Socket socket = new Socket(addressIP,8000);
ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
int id = Integer.parseInt(ID.getText());
String Names = name.getText();
int mobile =Integer.parseInt(Mobile.getText());
int phones = Integer.parseInt(phone.getText());
String addresss = address.getText();
PhoneBook p = new PhoneBook(id,Names,mobile,phones,addresss);
toServer.writeObject(p);
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
}
/**

