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 5848867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:55:11+00:00 2026-05-22T12:55:11+00:00

I am aware this code is rather messy. Copying an extraction of one list

  • 0

I am aware this code is rather messy. Copying an extraction of one list to another I’m pretty sure is not the most elegant of solutions. However I just want to work out why this does not work.

This is a hibernate method to query a db a return the enteries in a list. i.e the fix list. From this I only want the FixString which I wish to use to populate the fixString list.

However for reason unknown to me. whenever I call

try {
    //Get all the Fix Strings stored in db
        fixStrings = HibFunction.listFix();
    } catch (Exception e) {
        System.out.printf("Cannot get Fix strings",e);
    }

My junit fails giving me a console printout of



1 string



Cannot get Fix strings

And a Failute Trace of NullPointer…

Why is this equalling null despite being able to print out a result?

public static List<String> listFix()
    {
        List <String> fixString = null;
        List fix = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = null;
        try {
            transaction = session.beginTransaction();
             fix = session.createQuery("from metadataPoC.hib.TestHib").list();
            for (Iterator iterator = fix.iterator(); iterator.hasNext();)
            {
                TestHib fixtable = (TestHib) iterator.next();
                                System.out.println("****************************************************");
                System.out.println("****************************************************");
                System.out.println(fixtable.getFixString());
                System.out.println("****************************************************");
                System.out.println("****************************************************");
                fixString.add(fixtable.getFixString());

            }
            transaction.commit();           

        } catch (HibernateException e) {
            transaction.rollback();
            e.printStackTrace();
        } finally {
            session.close();
        }
        return fixString;
    }
  • 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-22T12:55:12+00:00Added an answer on May 22, 2026 at 12:55 pm

    Quickly looking at your code, it seems you are not initializing the

    List <String> fixString
    

    properly. It will be null when you invoke a method on it. So instead of

    List <String> fixString = null;
    

    initialize the list by, for example,

    List <String> fixString = new ArrayList<String>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic method with this (dummy) code (yes I'm aware IList has
Not many are aware of this feature, but Python's functions (and methods) can have
I think this might be a classic question but I am not aware of
I'm aware that SQL injection is rather dangerous . Now in my C# code
I'm aware some of you may not be familiar with Monotouch, but this could
First off, I'm aware this is a bad practice and I have answered many
I aware that this will be a less programming question, but still... How can
I am aware of this command: cvs log -N -w<userid> -d1 day ago Unfortunately
I have created a basic WCF service in IIS. I am aware that this
I'm aware that you can do this: public ActionResult DoSomething([Bind(Exclude = CreationDate)] Item item)

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.