Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2006

Tip: Looking for answers? Try searching our database.

DefaultStyledDocument array problem

Thread view: 
Charly Si - 28 May 2006 16:10 GMT
Using Java 5.0
  In class PublishStats extends JFrame I have

   <<DefaultStyledDocument doc = new DefaultStyledDocument[4];>>

  In method public void UpdateFields(String[][] tabDat) I have

   <<
   for (int i = 0; i < 4; i++)
     {
       doc[i].insertString(doc[i].getLength(), tabDat[wgr][i], stdStyle);
     }
   >>

This will not compile:
 Incompatible types.
 found :javax.swing.text.DefaultStyledDocument[]
 required: javax.swing.test.DefaultStyleDocument
 with an up arrow under "new"

What am I doing wrong and how can I correct it?
Bart Cremers - 29 May 2006 07:59 GMT
In DefaultStyledDocument doc = new DefaultStyledDocument[4];
you're trying to assign an array to a variable of type
DefaultStyledDocument. You'll have to declare the variable as an array.

DefaultStyledDocument[] doc = new DefaultStyledDocument[4];

Don't forget you'll need to initialize every element of the array
before you can use it (all elements are 'null' by default).

Bart
HarryGuy - 29 May 2006 14:36 GMT
Thanks for the help. It now compiles OK, but when I run it I get a
NullPointerExecption on the line reading :

 <<wagerDoc[i].insertString(wagerDoc[i].getLength(), tabDat[wgr][i],
stdStyle);>>

Do you have any ideas on that?

> In DefaultStyledDocument doc = new DefaultStyledDocument[4];
> you're trying to assign an array to a variable of type
[quoted text clipped - 6 lines]
>
> Bart
Oliver Wong - 29 May 2006 21:12 GMT
> Thanks for the help. It now compiles OK, but when I run it I get a
> NullPointerExecption on the line reading :
[quoted text clipped - 3 lines]
>
> Do you have any ideas on that?

Bart answered that one already:

>> Don't forget you'll need to initialize every element of the array
>> before you can use it (all elements are 'null' by default).

   If you have a Java textbook handy, you might want to review the section
on arrays. The problem doesn't actually have anything to do with
DefaultStyledDocument.

   - Oliver
Charly Si - 30 May 2006 17:35 GMT
Right! I realized that after I posted. It's working OK now. Thanks to both.

>> Thanks for the help. It now compiles OK, but when I run it I get a
>> NullPointerExecption on the line reading :
[quoted text clipped - 14 lines]
>
>    - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.