Rewrite getColumnName () method Error Java.lang.StackOverflowError

Source: Internet
Author: User

I initialized a column name in a method and added a column name

New Vector ();        Columnnames.add ("School Number");        Columnnames.add ("name");        Columnnames.add ("gender");        Columnnames.add ("age");        Columnnames.add ("birthplace");        Columnnames.add ("department");

Because you need to display column names in JTable, you need to override the getColumnName method in Abstracttablemodel.

@Override      Public String getColumnName (int  column) {        //return (String) this.columnNames.get (column );        return  This . getColumnName (column);    }

Run, Error:Exception in thread "main" Java.lang.StackOverflowError

It's embarrassing. First, I guess it might be a way to get the length of a column getcolumncount problem.

@Override      Public int getColumnCount () {        returnthis. Columnnames.size ();    }

But on the console output, the result is equal to 6. Well, that's not the problem. Look for a question after the return statement.

First enter this in the getColumnName method, followed by return.

Look at the tool to give me the hint, found that there are columnnames, choose this again "." I found a GET method, it needs to pass a parameter, just int, so I have a bold idea.

@Override      Public String getcolumnname (int  column) {        returnthis. Columnnames.get (column);    }

OK, write well, run a bit, the name of the list is not defective display.

Very happy, solve the problem, by the way to write this article, the Java small white to record my problem-solving ideas.

Rewrite getColumnName () method Error Java.lang.StackOverflowError

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.