Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. How to solve this, always get error

How to solve this, always get error

Scheduled Pinned Locked Moved Java
helpjavadatabasetestingbeta-testing
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tan873
    wrote on last edited by
    #1

    I have a problem when i get value from another class, the error message show "unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown" This is my main code package testtimer; import testing.testing_1234; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.Timer; import java.util.Date; import java.io.*; import java.text.*; import java.util.*; import java.sql.*; import javax.swing.*; import javax.swing.JTable; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.util.Iterator; /** * * @author tan */ public class testing_page extends javax.swing.JFrame { testing_1234 appsetting = new testing_1234(); String strc=appsetting.getcname(); public rxpooltesting() { initComponents(); } @SuppressWarnings("unchecked") private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); pack(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new testing_page().setVisible(true); } }); } } This is my class: package testing; import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; import java.io.FileWriter; import java.io.BufferedWriter; import java.util.Properties; import java.io.FileNotFoundException; public class readsetting { private String PropertiesPath = "C:TestTimer/src/testtimer/setting.properties"; private String strcname; public readsetting() { } public readsetting(String strurl,String struname,String strpword,String strcname,String strxpool, String stridcounter,String strtemppol,String strxlog,String strlogfile,String strDB, String strservice) {} public String getcname() throw

    B 1 Reply Last reply
    0
    • T tan873

      I have a problem when i get value from another class, the error message show "unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown" This is my main code package testtimer; import testing.testing_1234; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.Timer; import java.util.Date; import java.io.*; import java.text.*; import java.util.*; import java.sql.*; import javax.swing.*; import javax.swing.JTable; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.util.Iterator; /** * * @author tan */ public class testing_page extends javax.swing.JFrame { testing_1234 appsetting = new testing_1234(); String strc=appsetting.getcname(); public rxpooltesting() { initComponents(); } @SuppressWarnings("unchecked") private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); pack(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new testing_page().setVisible(true); } }); } } This is my class: package testing; import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; import java.io.FileWriter; import java.io.BufferedWriter; import java.util.Properties; import java.io.FileNotFoundException; public class readsetting { private String PropertiesPath = "C:TestTimer/src/testtimer/setting.properties"; private String strcname; public readsetting() { } public readsetting(String strurl,String struname,String strpword,String strcname,String strxpool, String stridcounter,String strtemppol,String strxlog,String strlogfile,String strDB, String strservice) {} public String getcname() throw

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      Did you actually read the error message? getcname declares thrown exceptions, so you have to catch or declare them as thrown wherever you call it. That means you can't use getcname in a static initialiser, because there's no way to catch the exception.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups