I am working on a java application using netbeans,
I face a porblem.
I want to display the output of my program, on jtextarea
(i have designed a jtextarea,) just I want to display the output
namely the content of an array.
plz can anyone help?

Use JTextArea methods append(String str) or setText(String str). Nothing big.

I know the methods, but when i use them they throws java.lang.NullPointerException

Then show this piece of code where You created JTextArea and want to append some text.

I know the methods, but when i use them they throws java.lang.NullPointerException

You get that exception because you haven't initialized the objects. You have create something with "new" in order to use it.

thank you, i initialize an object but another problem appears which is the text area doesn't show anything it is empty

Basically displaying text on jTextArea is not a difficult thing to do. Maybe there is a minute error to be fixed. Pls post your code so that we can check it!


I think javaAddict conveyed that same point with his post. Please don't repeat people for the sake of posting (unless you're adding something to the discussion), otherwise, you'll become like adatapost.

Sorry...thanx for reminding that. I posted that coz i missed that #7 post by javaAddict. I just noticed that when u said now. If i had seen that earlier i wouldn't have posted what i have posted. M not an echoer. However thx!

class cluster{
 public Cluster(int i, String name){
            cName = name;
            featureNumber[0] = i;
            for(int c=0;c<7;c++)

public void print(Cluster cl, javax.swing.JTextArea a){
       System.out.println(cl.cName + "has " + cl.n + "Features:");
       for (int r=0;r<cl.n;r++){
             System.out.println("Feature: " +  cl.featureNumber[r]);
           a.append("Feature Number: " + Integer.toString(cl.featureNumber[r]));

the class which call the orint method

class Result{

  public static void main(String args[]) {

        final Cluster cluster1 = new Cluster(0,"cluster1");
        final Cluster cluster2 = new Cluster(1, "cluster2");
        final Cluster cluster3 = new Cluster(2, "cluster3");

      // where r.c1, r.c2, r.c3 are text area which i desighned using netbeans
      // where all test areas are public defined

      final Result r = new Result();
       cluster1.print(cluster1, r.c1);
       cluster2.print(cluster2, r.c2);
       cluster3.print(cluster3, r.c3);


Where do instantiate the JTextArea? It should be somewhere were is "visible"(not out of scope) form your main. Also if you want it to be displayed you need to attach it to a JPanel, the JPanel to a JFrame and then you need to instantiate the JFrame and set it to be visible. JTextArea will not be displayed no its own