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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:36:01+00:00 2026-06-12T03:36:01+00:00

here is my snippet.It returns a null pointer exception..jlabel1 is already set and working

  • 0

here is my snippet.It returns a null pointer exception..jlabel1 is already set and working

JLabel j[]=new JLabel[10];
i=0;    
j[i]=new JLabel();
j[i].setText("1");
this.add(j[i]);

Edit (from the comments)

JLabel j[]=new JLabel[50]; 
try { 
  Rectangle bounds = jLabel1.getBounds(); 
  j[i].setText("1"); 
  this.add(j[i]); 
  j[i].setBounds(jLabel1.getX(),jLabel1.getY()+50 ,jLabel1.getHeight(),jLabel1.getWidth()); } catch(Exception e) { 
  System.out.println(e.toString()); 
} 
  • 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-06-12T03:36:02+00:00Added an answer on June 12, 2026 at 3:36 am

    The problem is that you forgot the

    j[i] = new JLabel();
    

    in the snippet you posted in the comments (although it was included in your question).

    A NullPointerException is typically easy to debug as you just have to follow the stack trace to discover what exactly is null. When in doubt, you just place a breakpoint on that line and use a debugger.

    To obtain the stacktrace, you can use e.printStackTrace() or simply remove the try catch block (as it is bad practice to simply have a try catch block for all exceptions)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this snippet of code here. The intention is to make a copy
Consider this snippet of Objective-C: NSString *elementString = nil; if(elementText != NULL) { elementString
Here's a snippet of code I saw on the web and I'm wondering if
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here's a snippet of a script of mine attempting to put extra Unicode awesomeness
Here is a snippet of the official Apple Documentation of AudioBufferList (Core Audio Data
Here is a snippet of my code $fp = fsockopen($s['url'], 80, $errno, $errstr, 5);
Here is a snippet from a Sinatra app where users will be submitting urls.
So here's a snippet of my code. void RoutingProtocolImpl::removeAllInfinity() { dv.erase(std::remove_if(dv.begin(), dv.end(), hasInfCost), dv.end());
So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned

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.