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 7 of 7

Thread: Urgent ::: unreported exception java.lang.Exception

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Urgent ::: unreported exception java.lang.Exception

    Hi guys, I'm new in java...
    Please help me to solve this issue... was stuck here almost 7 hours.
    I will be waiting online.
    Really thanks...


    following is my coding
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
     
    import java.io.*;
     
    public class NextPage extends JFrame
    {
    	//instance variables
    	private JPanel addPanel = new JPanel();
       	private JLabel 	welcomeLabel,welcomeLabel1,welcomeLabel2;
    	private JButton addButton,viewButton,searchButton, deleteButton;
     
    	public NextPage() {
     
    		setTitle("MANs Fashion cutomer database");
    		setSize (350, 400);
     
    		//creating label object
    		addPanel.setLayout (null);
    		welcomeLabel = new JLabel("MANs Fashion");
    		welcomeLabel.setBounds(65,10,200,25);
     
     
    		//creating textfield object
    		addButton = new JButton("Add Customer Record");
    		addButton.setBounds(70,130,200,25);
     
    		thehandler handler = new thehandler();
    		addButton.addActionListener(handler);
     
    		addPanel.add(welcomeLabel);
    		addPanel.add(addButton);
    		addPanel.add(viewButton);
    		addPanel.add(searchButton);
    		addPanel.add(deleteButton);
     
    		getContentPane().add (addPanel);
    		setVisible (true);
    	}
     
    	private class thehandler implements ActionListener{
    		public void actionPerformed(ActionEvent event){
     
    			if(event.getSource() == addButton){
    				addrecord addRec = new addrecord();
    			}
    		}
    	}
     
    	public static void main(String args[])throws Exception{
    		NextPage updatecus = new NextPage();
    		}
    }
    Last edited by copeg; March 25th, 2011 at 02:17 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Urgent ::: unreported exception java.lang.Exception

    First, please use the code tags when posting code (see my signature). Second, if you are receiving an Exception, post the full stack trace - it has important information that should never be ignored. Lastly, see Ease Up at JavaRanch and How To Ask Questions The Smart Way

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Urgent ::: unreported exception java.lang.Exception

    oops... sorry Im new here.
    thanks for replaying me..following is the error.


    java:47: unreported exception java.lang.Exception; must be caught or declared to be thrown
    addrecord addRec = new addrecord();
    ^
    1 error

    Tool completed with exit code 1

    and this is my another coding,
    import javax.swing.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.event.*;
     
    public class addrecord extends JFrame implements ActionListener
    {
     
    JLabel l1,l2,l3,l4,l5,l6,l7;
    JTextField t1,t2,t3,t4;
    JTextArea t5,t6;
    JButton btnAdd,btnClear,btnExit;
    JPanel p1;
     
    RandomAccessFile data;
    int counter = 0;
    String id[] = new String[20];
    String joined[] = new String[20];
    String name[] = new String[100];
    String phone[] =new String[13];
    String address[] = new String[100];
    String additional[] = new String[200];
     
    public addrecord() throws Exception
    	{
     
    	data = new RandomAccessFile("staff.dat","rw");
    	counter = data.readInt();
    	for(int x=0; x < counter; x++)
    		{
    		id[x] = data.readUTF();
    		joined[x] = data.readUTF();
    		name[x] = data.readUTF();
    		phone[x] = data.readUTF();
    		address[x] = data.readUTF();
    		additional[x] = data.readUTF();
    		}
     
    	data.close();
     
    	setTitle("ADD RECORD");
    	setSize(600,400);
    	setResizable(true);
    	setVisible(true);
     
    	l1 = new JLabel("Cust ID :");
    	l1.setBounds(30,40,150,25);
    	l2 = new JLabel("Cust Joined Date :");
    	l2.setBounds(30,70,200,25);
    	l3 = new JLabel("Cust Name :");
    	l3.setBounds(30,100,200,25);
    	l4 = new JLabel("Cust Contatc No. :");
    	l4.setBounds(30,130,200,25);
    	l5 = new JLabel("Cust Address :");
    	l5.setBounds(30,160,200,25);
    	l6 = new JLabel("Additional Info :");
    	l6.setBounds(30,230,200,25);
    	l7 = new JLabel("Add Record");
    	l7.setBounds(130,5,150,25);
     
    	t1 = new JTextField();
    	t1.setBounds(150,40,200,25);
    	t2 = new JTextField();
    	t2.setBounds(150,70,200,25);
    	t3 = new JTextField();
    	t3.setBounds(150,100,200,25);
    	t4 = new JTextField();
    	t4.setBounds(150,130,200,25);
    	t5 = new JTextArea();
    	JScrollPane addressScrollPane = new JScrollPane(t5, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    	addressScrollPane.setBounds(150,160,250,65);
    	t6 = new JTextArea();
    	JScrollPane additionalScrollPane = new JScrollPane(t6, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    	additionalScrollPane.setBounds(150,230,300,65);
     
    	btnAdd = new JButton("Add");
    	btnAdd.setBounds(50,310,100,25);
    	btnClear = new JButton("Clear");
    	btnClear.setBounds(160,310,100,25);
    	btnExit = new JButton("Exit");
    	btnExit.setBounds(270,310,100,25);
    	btnAdd.addActionListener(this);
    	btnClear.addActionListener(this);
    	btnExit.addActionListener(this);
     
    	p1 = new JPanel();
    	p1.setLayout(null);
    	p1.add(l1);
    	p1.add(l2);
    	p1.add(l3);
    	p1.add(l4);
    	p1.add(l5);
    	p1.add(l6);
    	p1.add(l7);
    	p1.add(t1);
    	p1.add(t2);
    	p1.add(t3);
    	p1.add(t4);
    	p1.add(addressScrollPane);
    	p1.add(additionalScrollPane);
    	p1.add(btnAdd);
    	p1.add(btnClear);
    	p1.add(btnExit);
    getContentPane().add (p1);
    	}
     
     
     
    public void actionPerformed(ActionEvent e)
    	{
    	if (e.getSource() == btnAdd)
    		{
    			id[counter] = t1.getText();
    			joined[counter] = t2.getText();
    			name[counter] = t3.getText();
    			phone[counter] = t4.getText();
    			address[counter] = t5.getText();
    			additional[counter] = t6.getText();
    			counter++;
     
    		try {
    					data = new RandomAccessFile("staff.dat","rw");
    					data.writeInt(counter);
    					for(int x=0; x < counter; x++)
    						{
    						data.writeUTF(id[x]);
    						data.writeUTF(joined[x]);
    						data.writeUTF(name[x]);
    						data.writeUTF(phone[x]);
    						data.writeUTF(address[x]);
    						data.writeUTF(additional[x]);
    						}
     
    					data.close();
    					JOptionPane.showMessageDialog(null, "File Saved !!");
    		} catch (Exception w){JOptionPane.showMessageDialog(null, "File unable to saved !!");}
     
    		}
     
    	else if (e.getSource() == btnClear)
    		{
    			t1.setText("");
    			t2.setText("");
    			t3.setText("");
    			t4.setText("");
    			t5.setText("");
    			t6.setText("");
    		}
     
    	else if (e.getSource() == btnExit)
    		{
    			System.exit(0);
    		}
    	}
     
     
     
    //public static void main(String args[]) throws Exception
    	//{
    	//addrecord add = new addrecord();
    //	}
     
    }

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Urgent ::: unreported exception java.lang.Exception

    Seems you are throwing (or something throws) an Exception which must be caught...so catch it. Suggested reading: Lesson: Exceptions (The Java™ Tutorials > Essential Classes)

  5. The Following User Says Thank You to copeg For This Useful Post:

    kolo854 (March 25th, 2011)

  6. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Urgent ::: unreported exception java.lang.Exception

    Hi,,,
    How should I catch it??
    initially I use the "public static void main(String args[]) throws Exception" it is find.

  7. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Urgent ::: unreported exception java.lang.Exception

    please advise me..
    Thanks.

  8. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Urgent ::: unreported exception java.lang.Exception

    hi.. Thanks you so much. appreciated
    finally found the problem where it is.

    was the throws exception "public addrecord() throws Exception", running find after I change it to try and catch.

Similar Threads

  1. exception in thread main java.lang.Nullpointerexception
    By westandeast in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 6th, 2011, 09:08 AM
  2. Exception in thread "main" java.lang.NullPointerException
    By MryJaho in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 4th, 2011, 05:36 PM
  3. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  4. Please help! Exception in thread "main" java.lang.NullPointerException
    By Arutha2321 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 18th, 2009, 02:25 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM