Results 1 to 9 of 9
  1. #1
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Uncaught error. What's this? (big headache!)

    Java Code:
     
    
    package OOPJ.ui;
    
    
    import javax.swing.JPanel;
    import java.awt.Color;
    import javax.swing.JLabel;
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.Font;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.ArrayList;
    import javax.swing.DefaultListModel;
    import javax.swing.JOptionPane;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;
    import javax.swing.SwingConstants;
    import javax.swing.ImageIcon;
    import javax.swing.JTextField;
    import javax.swing.JButton;
    import Signup.entity.SignUp;
    import cancer.entity.CancerDetails;
    import javax.swing.JList;
    
    
    public class CancerPanel extends JPanel {
    		
    	private static final long serialVersionUID = 1L;
    	private JLabel jLabelLogo3 = null;
    	private JLabel jLabelSearch = null;
    	private JTextField jTextField1 = null;
    	private JLabel jLabelCancer = null;
    	private JButton jButtonGo = null;
    	private JLabel jLabelResults = null;
    	private JButton jButtonMenu = null;
    	private JLabel jLabelCancerImage1 = null;
    	private MainFrame myFrame = null;
    	private JButton jButtonEdit = null;
    	private DefaultListModel model;
    	private JList dbList = null;
    	private JScrollPane pane = null;
    	private static String result;
    	private static String c_articleTitle;
    
    	
    	/**
    	 * This is the default constructor
    	 */
    	public CancerPanel() {
    		super();
    		model = new DefaultListModel(); 
    		initialize();    
    	}
    	     
    	
    
    	public CancerPanel(MainFrame f) { 
    		this(); 
    		myFrame = f; 
    
    	}
    
    
    	private void initialize() {
    		jLabelCancerImage1 = new JLabel();
    		jLabelCancerImage1.setBounds(new Rectangle(334, 144, 326, 286));
    		jLabelCancerImage1.setIcon(new ImageIcon(getClass().getResource("/images/ui/images/cancer.jpg")));
    		jLabelCancerImage1.setText("JLabel");
    		jLabelResults = new JLabel();
    		jLabelResults.setBounds(new Rectangle(42, 149, 229, 30));
    		jLabelResults.setFont(new Font("Dialog", Font.BOLD, 18));
    		jLabelResults.setHorizontalAlignment(SwingConstants.CENTER);
    		jLabelResults.setHorizontalTextPosition(SwingConstants.CENTER);
    		jLabelResults.setText("Recommended Articles:");
    		jLabelCancer = new JLabel();
    		jLabelCancer.setBounds(new Rectangle(176, 8, 431, 70));
    		jLabelCancer.setFont(new Font("Dialog", Font.BOLD, 24));
    		jLabelCancer.setHorizontalAlignment(SwingConstants.CENTER);
    		jLabelCancer.setHorizontalTextPosition(SwingConstants.CENTER);
    		jLabelCancer.setIcon(new ImageIcon(getClass().getResource("/images/ui/images/Cancer Title.jpg")));
    		jLabelCancer.setText("");
    		jLabelSearch = new JLabel();
    		jLabelSearch.setBounds(new Rectangle(142, 88, 68, 26));
    		jLabelSearch.setHorizontalAlignment(SwingConstants.CENTER);
    		jLabelSearch.setHorizontalTextPosition(SwingConstants.CENTER);
    		jLabelSearch.setText("Search:");
    		jLabelLogo3 = new JLabel();
    		jLabelLogo3.setBounds(new Rectangle(14, 8, 137, 66));
    		jLabelLogo3.setFont(new Font("Dialog", Font.BOLD, 24));
    		jLabelLogo3.setHorizontalAlignment(SwingConstants.LEFT);
    		jLabelLogo3.setHorizontalTextPosition(SwingConstants.RIGHT);
    		jLabelLogo3.setIcon(new ImageIcon(getClass().getResource("/images/ui/images/logo.jpg")));
    		jLabelLogo3.setText("");
    		this.setLayout(null);
    		this.setSize(700, 500);
    		this.setBackground(Color.white);
    		this.add(jLabelLogo3, null);
    		this.add(jLabelSearch, null);
    		this.add(getJTextField1(), null);
    		this.add(jLabelCancer, null);
    		this.add(getJButtonGo(), null);
    		this.add(jLabelResults, null);
    		this.add(getJButtonMenu(), null);
    		this.add(jLabelCancerImage1, null);
    		this.add(getJButtonEdit(), null);
    		//this.add(getDbList(), null);
    		this.add(getDbList(), null);
    		this.add(getPane(), null);
    		//this.add(getPane(), null);
    	}
    
    	
    
    	private JTextField getJTextField1() {
    		if (jTextField1 == null) {
    			jTextField1 = new JTextField();
    			jTextField1.setBounds(new Rectangle(235, 85, 326, 28));
    		}
    		return jTextField1;
    	}
    
    	/**
    	 * This method initializes jButtonGo	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButtonGo() {
    		if (jButtonGo == null) {
    			jButtonGo = new JButton();
    			jButtonGo.setBounds(new Rectangle(576, 85, 53, 26));
    			jButtonGo.setText("GO");
    			jButtonGo.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    
    					String searchPhrase = jTextField1.getText();
    					
    					if (jTextField1.getText().trim().length() == 0) {
    					JOptionPane.showMessageDialog(null, "Do not leave the field empty", "Error", JOptionPane.ERROR_MESSAGE);	
    					} 
    					
    					else 
    					{
    						
    						 
    						pane.setToolTipText(result);
    						 ArrayList<CancerDetails> result = CancerDetails.searchCancer(searchPhrase);
    							System.out.println("count " +result.size()); 
    
    							
    							for (CancerDetails s : result) { 
    								System.out.println("getC_articleTitle" + s.getC_articleTitle());
    								model.addElement(s.getC_articleTitle());
    							}
    					}
    	
    					}
    			}
    
    					 );
    		}
    		return jButtonGo;
    	}
    	/**
    	 * This method initializes jButtonMenu	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButtonMenu() {
    		if (jButtonMenu == null) {
    			jButtonMenu = new JButton();
    			jButtonMenu.setBounds(new Rectangle(562, 440, 85, 34));
    			jButtonMenu.setFont(new Font("Dialog", Font.BOLD, 16));
    			jButtonMenu.setText("Menu");
    			jButtonMenu.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					JPanel panel = new MenuPanel(myFrame);
    					myFrame.getContentPane().removeAll();
    					myFrame.getContentPane().add(panel);
    					myFrame.getContentPane().validate();
    					myFrame.getContentPane().repaint();
    				}
    			});
    		}
    		return jButtonMenu;
    	}
    
    	/**
    	 * This method initializes jButtonEdit	
    	 * 	
    	 * @return javax.swing.JButton	
    	 */
    	private JButton getJButtonEdit() {
    		if (jButtonEdit == null) {
    			jButtonEdit = new JButton();
    			jButtonEdit.setBounds(new Rectangle(601, 15, 94, 32));
    			jButtonEdit.setText("Add");
    			jButtonEdit.addActionListener(new java.awt.event.ActionListener() {
    				public void actionPerformed(java.awt.event.ActionEvent e) {
    					JPanel panel = new CancerBackPanel(myFrame); 
    					myFrame.getContentPane().removeAll(); 
    					myFrame.getContentPane().add(panel);
    					myFrame.getContentPane().validate(); 
    					myFrame.getContentPane().repaint(); 
    				}
    			});
    		}
    		return jButtonEdit;
    	}
    
    
    	
    	private JList getDbList() {
    		if (dbList == null) {
    			
    			 dbList = new JList(model);
    			 dbList.setVisibleRowCount(5); 
    			 dbList.setBounds(new Rectangle(39, 199, 201, 106));
    			 dbList.setFixedCellHeight(27); 
    			 dbList.setFixedCellWidth(130); 
    			 dbList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    			 dbList.addMouseListener(new MouseAdapter(){
    			      public void mouseClicked(MouseEvent me){
    			        String cancer = (String) dbList.getSelectedValue();
    			        CancerDetails c1 = new CancerDetails();
    			        c1.retrieveCancer();
    			        ViewCancerFrame cancerFrame = new ViewCancerFrame(c1); 
    			        cancerFrame.setVisible(true);
    			      }
    
    				});
    			 
    		}
    		return dbList;
    	}
    
    	private JScrollPane getPane() {
    		if (pane == null) 
    		 pane = new JScrollPane();
    		 pane.getViewport().add(dbList);
    		 pane.setPreferredSize(new Dimension(250, 200));
    		 pane.setBounds(new Rectangle(27, 195, 281, 256));
    			
    		return pane;
    	} 
    }

    I was thinking maybe is it line 224 that is creating the error? but i dunno what to add in code to that line to solve my problem..
    Why when i want to retrieve data from the database when it always null?
    I had check with my entity class where the SQL Query code is at. it was all correct..
    Here is the error:

    Java Code:
     
    connection is jdbc:odbc:CFDatabase
    DB Query: SELECT * FROM CANCER WHERE c_articleTitle LIKE '%liver%'
    Connection is closed
    count 2
    getC_articleTitleliver cancer
    getC_articleTitleTreatment for liver cancer
    connection is jdbc:odbc:CFDatabase
    DB Query: SELECT * FROM CANCER WHERE C_ARTICLETITLE ='null'
    Connection is closed
    null
    Uncaught error fetching image:
    java.lang.NullPointerException
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.awt.image.FileImageSource.getDecoder(Unknown Source)
    	at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
    	at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
    	at sun.awt.image.ImageFetcher.run(Unknown Source)
    Last edited by mathidioticz; 01-31-2012 at 04:57 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: Uncaught error. What's this? (big headache!)

    Where is the word null be printed out? And the message following it?

    The stack trace doesn't show any lines from your code.

  3. #3
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: Uncaught error. What's this? (big headache!)

    The C_ARTICLETITLE is actually being retrieve out from the database and will be reflected on the JList for users to choose the different articles.

    However, now, the problem is that the C_ARTICLETITLE that is retrieving out is null.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Uncaught error. What's this? (big headache!)

    If it's the select statement that's the problem then shouldn't you show us that code?

  5. #5
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: Uncaught error. What's this? (big headache!)

    Here is the database code. I am using Microsoft Access.

    Java Code:
     
    
    package cancer.entity;
    
    import OOPJ.database.DBController; 
    import OOPJ.ui.MainFrame;
    import Signup.entity.SignUp;
    
    import java.awt.Container;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.sql.ResultSet; 
    import java.util.ArrayList; 
    import java.util.Scanner;
    
    import javax.swing.JFileChooser; 
    
    
    public class CancerDetails {
    
    	private  String c_articleTitle;
    	private  String c_articleDetails;
    	private  String c_image1;
    	private MainFrame myFrame = null; 
    
    	public CancerDetails(String cArticleTitle, String cArticleDetails,
    			String cImage1) {
    		super();
    		c_articleTitle = cArticleTitle;
    		c_articleDetails = cArticleDetails;
    		c_image1 = cImage1;
    	}
    
    	public CancerDetails(String cArticleTitle) {
    		super();
    		c_articleTitle = cArticleTitle;
    	}
    
    	public CancerDetails() {
    	
    	}
    	public CancerDetails(MainFrame f){ 
    		this(); 
    		myFrame = f; 
    	}
    	
    	public static void main (String[] args) {
    		CancerDetails f1 = new CancerDetails();
    		f1.setC_articleTitle("heyhey");
    		f1.setC_articleDetails("meow");
    		f1.setC_image1("johnson");
    		
    		System.out.println(f1.createCancer());
    		System.out.println(f1.getC_articleTitle());
    		//To test update friend
    		f1.setC_image1("Micheal");
    		System.out.println(f1.updateCancer());
    
    		//To test retrieve friend
    	    CancerDetails f2 = new CancerDetails();
    		f2.retrieveCancer();
    		System.out.println(f2.getC_articleDetails());
    		
    	}
    
    	public String getC_articleTitle() {
    		return c_articleTitle;
    	}
    
    	public void setC_articleTitle(String cArticleTitle) {
    		c_articleTitle = cArticleTitle;
    	}
    
    	public String getC_articleDetails() {
    		return c_articleDetails;
    	}
    
    	public void setC_articleDetails(String cArticleDetails) {
    		c_articleDetails = cArticleDetails;
    	}
    
    	public String getC_image1() {
    		return c_image1;
    	}
    
    	public void setC_image1(String cImage1) {
    		c_image1 = cImage1;
    	}
    
    	public boolean retrieveCancer() { 
    		//declare local variables
    		boolean success = false; 
    		ResultSet rs = null; 
    		DBController db =  new DBController();
    		
    		db.setUp("CFDatabase");
    		
    		String dbQuery = "SELECT * FROM CANCER WHERE c_articleTitle ='" + c_articleTitle +  "'";
    		
    		rs = db.readRequest(dbQuery); 
    		
    		try { 
    			if(rs.next()) { 
    				c_articleTitle = rs.getString("c_articleTitle");
    				c_articleDetails = rs.getString("c_articleDetails"); 
    				c_image1 = rs.getString("c_image1");
    				success = true; 
    			}
    		 
    	}
    		catch(Exception e) { 
    			e.printStackTrace();
    		}
    		db.terminate(); 
    		return success;
    	}
    	
    	public boolean createCancer() { 
    		boolean success = false; 
    		ResultSet rs = null; 
    		DBController db = new DBController(); 
    		String dbQuery; 
    		db.setUp("CFDatabase"); 
    
    		dbQuery = "INSERT INTO CANCER(c_articleTitle, c_articleDetails,";
    		dbQuery = dbQuery + " c_image1) VALUES (\'" + c_articleTitle + "', '" + c_articleDetails + "','" + c_image1 + "')";
    		
    	
    		
    		rs = db.updateRequestKey(dbQuery);
    		try{
    		if(rs.next()){
    			success = true;
    		}
    		}
    		
    		catch (Exception e){
    		e.printStackTrace();
    		}
    		db.terminate();
    		return success;
    		}
    	
    	public boolean updateCancer() { 
    		
    		boolean success = false; 
    		DBController db = new DBController(); 
    		
    		db.setUp("CFDatabase"); 
    		
    		String dbQuery = "UPDATE CANCER SET c_articleTitle = '" + c_articleTitle;
    		dbQuery = dbQuery + "', c_articleDetails= '" + c_articleDetails + "', c_image1= '" + c_image1 + "'";
    
    		
    		//step 2 of using DBController, use updateRequest method
    		if ( db.updateRequest(dbQuery) == 1){
    		success = true;
    		}
    		//step 3 of using DBController
    		db.terminate();
    		return success;
    		
    		}
    	
    	public static ArrayList<CancerDetails> searchCancer(String phrase){
    		// declare local variables
    		ArrayList<CancerDetails> cancerList = new ArrayList<CancerDetails>();
    		ResultSet rs = null;
    		DBController db = new DBController();
    		String dbQuery;
    		
    		// step 1 of using DBController, passing data source name setup during last practical
    		db.setUp("CFDatabase");
    			
    		//The symbol % is used as the wildcard.
    	      if (phrase == null || phrase == "")
    			dbQuery = "SELECT * FROM CANCER";
    		else
    			dbQuery = "SELECT * FROM CANCER WHERE c_articleTitle LIKE '%" + phrase + "%'";	
    			
    		// step 2 of using DBController, use updateRequest method 
    		rs = db.readRequest(dbQuery);
    		try{
    		   while (rs.next()){
    			   
    			   String title = rs.getString("c_articleTitle");
    				String details = rs.getString("c_articleDetails"); 
    				String image1 = rs.getString("c_image1");
    		        CancerDetails can = new CancerDetails(title, details, image1);   
    				cancerList.add(can);   
    		   }
    		}
    		
    		catch (Exception e) {
    		   e.printStackTrace();
    		}
    		// step 3 of using dbcontroller 
    		db.terminate();
    		return cancerList;
    	}
    
    	}

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Uncaught error. What's this? (big headache!)

    First off you should be using PreparedStatement and then binding values in.
    Concatenating your queries together like that is always prone to error.

    Second (and to the problem at hand):
    Java Code:
       CancerDetails f2 = new CancerDetails();
       f2.retrieveCancer();
    WHen calling retrieve here what values will the attributes of f2 have?

  7. #7
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: Uncaught error. What's this? (big headache!)

    The f2 value should have c_articleTitle, c_articleDetails and c_image1

    so is it like this??

    Java Code:
     
    CancerDetails c2 = new CancerDetails(c2.getC_articleTitle(), c2.getC_articleDetails(), c2.getC_image1());
    c2.retrieveCancer();
    Last edited by mathidioticz; 01-31-2012 at 06:17 PM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Uncaught error. What's this? (big headache!)

    They'll all be null because you never set them.

    Your example won't compile.

    Compare what you do with f1.

  9. #9
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: Uncaught error. What's this? (big headache!)

    ThankYou for your help, i know where is the place that appears to be null already. ThankYou! :D

Similar Threads

  1. Uncaught error fetching image
    By Manfizy in forum New To Java
    Replies: 9
    Last Post: 12-03-2011, 05:16 PM
  2. NullPointerException Headache
    By denno in forum New To Java
    Replies: 17
    Last Post: 04-05-2011, 09:13 AM
  3. Uncaught error fetching image
    By dyelax in forum New To Java
    Replies: 8
    Last Post: 03-21-2011, 01:06 AM
  4. Modulo Headache
    By House in forum New To Java
    Replies: 17
    Last Post: 09-01-2010, 04:29 AM
  5. Event headache
    By kammenos in forum Java Applets
    Replies: 2
    Last Post: 12-13-2008, 12:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •