Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.text.TextSelection
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.text.TextSelection [message #905732] Fri, 31 August 2012 01:11 Go to next message
zhang lei is currently offline zhang leiFriend
Messages: 22
Registered: July 2012
Junior Member
I am learing the Jface in action.in the chapter 5,I get a mistake that annoyed me.I'm gettting the below error, please help me on this.
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.text.TextSelection
at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2701)
at org.eclipse.jface.text.TextViewer$5.run(TextViewer.java:2682)
at org.eclipse.swt.widgets.Display.runTimer(Unknown Source)
at org.eclipse.swt.widgets.Display.messageProc(Unknown Source)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.swtjface.Ch2.WidgetWindow.main(WidgetWindow.java:48)

the main class CompViewer

import org.eclipse.jface.window.*;
import org.eclipse.swt.widgets.*;
public class CompViewer extends ApplicationWindow 
{
  public CompViewer() 
  {
    super(null);
  }
  protected Control createContents(Composite parent) 
  {
	  Ch5CompletionEditor cc1 = new Ch5CompletionEditor(parent);
      return parent;
  }
  public static void main(String[] args) 
  {
    CompViewer cv = new CompViewer();
    cv.setBlockOnOpen(true);
    cv.open();
    Display.getCurrent().dispose();
  }
}


import java.util.StringTokenizer;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
public class Ch5CompletionEditor extends Composite
{
  private TextViewer textViewer;
  private WordTracker wordTracker;
  private static final int MAX_QUEUE_SIZE = 200;
  public Ch5CompletionEditor(Composite parent)
  {
    super(parent, SWT.NULL);
    wordTracker = new WordTracker(MAX_QUEUE_SIZE);
    buildControls();
  }
  private void buildControls()
  {
    setLayout(new FillLayout());
    textViewer = new TextViewer(this, SWT.MULTI | SWT.V_SCROLL);    
    textViewer.setDocument(new Document()); 
    final ContentAssistant assistant = new ContentAssistant();
    assistant.setContentAssistProcessor(
                new RecentWordContentAssistProcessor(wordTracker), 
                IDocument.DEFAULT_CONTENT_TYPE);  
    assistant.install(textViewer);
    textViewer.getControl().addKeyListener(new KeyAdapter() {
      public void keyPressed(KeyEvent e)
      {
        switch(e.keyCode)
        {
          case SWT.F1:
            assistant.showPossibleCompletions();  
            break;
          default:
            //ignore everything else
        }
      }
    });
    textViewer.addTextListener(new ITextListener() {
        public void textChanged(TextEvent e)
        {
          if(isWhitespaceString(e.getText())) 
          {
            wordTracker.add(findMostRecentWord(e.getOffset() - 1));
          }
        }
      });
    }
    protected String findMostRecentWord(int startSearchOffset)
    {
      System.out.println("findMostRecentWord()");
      int currOffset = startSearchOffset;
      char currChar;
      String word = "";
      try
      {
          while(currOffset > 0
                && !Character.isWhitespace(  
                      currChar = textViewer.getDocument()
                                            .getChar(currOffset)
                ))
          {
            word = currChar + word;
            currOffset--;
          }
          return word;
        }
        catch (BadLocationException e)
        {
          e.printStackTrace();
          return null;
        }
      }
      protected boolean isWhitespaceString(String string)
      {
        StringTokenizer tokenizer = new StringTokenizer(string);
        //if there is at least 1 token, this string is not whitespace
        return !tokenizer.hasMoreTokens();
      }
    }


import java.util.*;
public class WordTracker
{
  private int maxQueueSize;
  private List wordBuffer;
  private Map knownWords = new HashMap();
  
  public WordTracker(int queueSize)
  {
    maxQueueSize = queueSize;
    wordBuffer = new LinkedList();
  }
  public int getWordCount()
  {
    return wordBuffer.size();
  }
  public void add(String word)
  {
	    if( wordIsNotKnown(word) )
	    {
	      flushOldestWord();
	      insertNewWord(word);
	    }
	  }
	  private void insertNewWord(String word)
	  {
	    wordBuffer.add(0, word);
	    knownWords.put(word, word);
	  }
	  private void flushOldestWord()
	  {
	    if( wordBuffer.size() == maxQueueSize )
	    {
	      String removedWord = 
	              (String)wordBuffer.remove(maxQueueSize - 1);
	      knownWords.remove(removedWord);
	    }
	  }
	  private boolean wordIsNotKnown(String word)
	  {
	    return knownWords.get(word) == null;
	  }
	  public List suggest(String word)
	  {
	    List suggestions = new LinkedList();
	    for( Iterator i = wordBuffer.iterator(); i.hasNext(); )
	    {
	      String currWord = (String)i.next();
	      if( currWord.startsWith(word) )
	      {
	        suggestions.add(currWord);
	      }
	    }
	    return suggestions;
	  }
	}


import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.text.*;
import org.eclipse.jface.text.contentassist.*;

public class RecentWordContentAssistProcessor
  implements IContentAssistProcessor
{
  private String lastError = null;
  private IContextInformationValidator contextInfoValidator;
  private WordTracker wordTracker;
  public RecentWordContentAssistProcessor(WordTracker tracker)
  {
    super();
    contextInfoValidator = new ContextInformationValidator(this);
    wordTracker = tracker;
    System.out.println("RecentWordContentAssistProcessor()");
  }
  public ICompletionProposal[] computeCompletionProposals(
    ITextViewer textViewer,
    int documentOffset)
  {
	  System.out.println("computeCompletionProposals()");
    IDocument document = textViewer.getDocument();
    int currOffset = documentOffset - 1;
    try
    {
      String currWord = "";
      char currChar;
      while( currOffset > 0  
              && !Character.isWhitespace(
                    currChar = document.getChar(currOffset)) )
      {
        currWord = currChar + currWord;
        currOffset--; 
      }
      List suggestions = wordTracker.suggest(currWord);
      ICompletionProposal[] proposals = null;
      if(suggestions.size() > 0)
      {
        proposals = buildProposals(suggestions, currWord, 
                            documentOffset - currWord.length());
        lastError = null;
      }
      return proposals;
    }
    catch (BadLocationException e)
    {
      e.printStackTrace();
      lastError = e.getMessage();
      return null;
    }
  }
  private ICompletionProposal[] buildProposals(List suggestions, 
                                               String replacedWord, 
                                               int offset)
  {
    ICompletionProposal[] proposals = 
                  new ICompletionProposal[suggestions.size()];
    int index = 0;
    for(Iterator i = suggestions.iterator(); i.hasNext();)
    {
      String currSuggestion = (String)i.next();
      proposals[index] = new CompletionProposal( 
                                        currSuggestion, 
                                        offset, 
                                        replacedWord.length(), 
                                        currSuggestion.length());
      index++;
    }
    return proposals;
  }
  public IContextInformation[] computeContextInformation(
		    ITextViewer textViewer,
		    int documentOffset)
		  {
		    lastError = "No Context Information available";
		    return null;
		  }
		  public char[] getCompletionProposalAutoActivationCharacters()
		  {
		    //we always wait for the user to explicitly trigger completion
		    return null;
		  }
		  public char[] getContextInformationAutoActivationCharacters()
		  {
		    //we have no context information
		    return null;
		  }
		  public String getErrorMessage()
		  {
			    return lastError;
		  }
		  public IContextInformationValidator getContextInformationValidator()
		  {
		    return contextInfoValidator;
		  }
		}
  • Attachment: Ch5.rar
    (Size: 3.13KB, Downloaded 270 times)
Re: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.text.TextSelection [message #908620 is a reply to message #905732] Wed, 05 September 2012 17:02 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 242
Registered: July 2009
Senior Member
My guess: you're not including the org.eclipse.jface.text bundle and so the class isn't being found.

You can see the bundle that contains a class by using the Open Type dialog (Ctrl-Shift-T): type in the name, highlight the matching class and look at the status section below.

Brian.
Previous Topic:Treeviewer expander gives false indication
Next Topic:JFace Texteditor - Custom Undo
Goto Forum:
  


Current Time: Tue Mar 19 02:31:21 GMT 2024

Powered by FUDForum. Page generated in 0.01591 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top