Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6174685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:47:38+00:00 2026-05-23T23:47:38+00:00

I have the following try catch block that executes on a button click. try

  • 0

I have the following try catch block that executes on a button click.

  try {
//picking up the file I want to read in
 BufferedReader in = new BufferedReader(new FileReader("C:\\users\\me\\desktop\\blah.txt"));
 String line;                                           
 try {
    //read through the file until there is nothing left and add each line to list
         while((line = in.readLine()) != null){  
            jList1.add(line, jList1);
                    }

               } catch (IOException ex) {
                    Logger.getLogger(Frame2.class.getName()).log(Level.SEVERE, null, ex);
           }
      } catch (FileNotFoundException ex) {
                Logger.getLogger(Frame2.class.getName()).log(Level.SEVERE, null, ex);
  }

I can successfully System.out.println(line) so I know something is working right. I am unable to populate the list with the lines from the text file. The above code tells me I cannot add containers parent to self.

Attempting to find more information has only confused me more. I have come across some places that say jLists are more complciated than this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:47:38+00:00Added an answer on May 23, 2026 at 11:47 pm

    There are many mistakes present, too many to comment on all of them:

    1) Basic I/O

    2) Exceptions

    3) How to Use Lists

    4) Examples

        BufferedReader in = null;
        String line;
        DefaultListModel listModel = new DefaultListModel();
        try {
            in = new BufferedReader(new FileReader("C:\\users\\me\\desktop\\blah.txt"));
            while ((line = in.readLine()) != null) {
                listModel.addElement(line); //(String.valueof(line));
            }
        } catch (IOException ex) {
            Logger.getLogger(Frame2.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (in != null) {
                in.close();
            }
        }
        JList jList1 = new JList(listModel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: try { FileStream FS = new FileStream(this.InFile, FileMode.Open, FileAccess.Read);
I have a try-catch block that iterates over a set of records like this:
We have following code: try { // some code throwing MyException } catch (MyException
If in my code I have the following snippet: try { doSomething(); } catch
Background: Suppose I have the following obviously-incorrect PHP: try{ $vtest = ''; print(array_pop($vtest)); }catch(Exception
I have question about try, catch and finally in Java. Consider the following scenario:
I have an ASP.Net application with the following code: try { sql = new
I have the following block of code that works just fine: <%@page import="java.util.*" %>
I have a method that looks like this: try { doStuff(); } catch (Exception
I have a text file that contains meta-urls in the following form: http://www.xyz.com/.*services/ http://www.xyz.com/.*/wireless

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.