Thursday, September 22, 2011

Eclipse Content Assist Not Working

Eclipse sometimes goes clueless on assisting content when Ctrl + Space is pressed. Either it does'nt pops up the list, or else the popped up list would be empty without any suggestions. This can happen in any version of the eclipse begining from 3.2 to the latest 3.7 Eclipse Indigo. This is not due to the bug in eclipse. Its all about the configuration of eclipse editor and the Java project. Below are the four possible solutions that can help the user to get back the content assist

1.Create a New workspace project in Eclipse
Create a totally new workspace and import your existing project. Remember check “Copy projects into workspace” to copy all your existing work to new workspace.

2. Check the Content Assist Configuration
Configure Eclipse’s content assist, go “Preferences>Java>Editor>Content Assist>Advanced“. Make sure “1
Other Java Proposals” is ticked

3. Change Regional Setting option in Windows
Make sure “regional and language options” is in English language. For example, Windows, Control panel –> Region and language options –> Advance tab –> Language for non-unicode program –> Make sure English (United States) is selected.

4. Check the Lib folder in Current Project
Scenario -
There might be some class references with same name inside the jar's that are included in the library, or there might be chance of same "xyz.jar" included in two or more library jar's in the current project lib folder.
Solution -
1. Keep only one "xyz.jar". Remove "xyz.jar" from the jar's that include it, and keep only in current project lib.
2. Include it in any one of jar's inside the lib.

Wednesday, September 14, 2011

vlcj player with SWT


Find below the vlcj player embedding inside the eclipse plugin. It takes only few lines to get it embedded. The videocomposite below created should always be SWT.EMBEDDED, otherwise, it may give "Invalid Arugument" Error. For compiling and running add vlcj library and its dependecies JNA.jar and platform.jar libraries to the project. These libraries can be donwloaded from below reference.


/*VLC Player*/
org.eclipse.swt.widgets.Composite videoComposite = new org.eclipse.swt.widgets.Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
java.awt.Frame videoFrame = SWT_AWT.new_Frame(videoComposite);
java.awt.Canvas playerCanvas = new java.awt.Canvas();
playerCanvas.setBackground(java.awt.Color.black);
videoFrame.add(playerCanvas);
MediaPlayerFactory mpFactory = new MediaPlayerFactory();
EmbeddedMediaPlayer vlcPlayer = mpFactory.newMediaPlayer(null);
videoComposite.setBounds(5,5, 560,244);
videoComposite.setVisible(true);

ePlayer.setVideoSurface(playerCanvas);
/*end */


Additional reference
Java bindings for vlc media player
http://code.google.com/p/vlcj
http://code.google.com/p/vlcj/wiki/SwtExample
vlcj sources can be downloaded from
http://www.capricasoftware.co.uk/vlcj/downloads.php
vlcj tutorial
http://www.capricasoftware.co.uk/vlcj/tutorial.php

Tuesday, September 6, 2011

Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load library

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)



Scenario
The above is the error sometimes we get, when we try to load a DLL built using Microsoft Visual Studio. This error commonly happens when, one try to load a DLL built on his/her PC and distribute to others. In such situation, the library will be successfully loaded in the source machine in which the DLL is built, but will fail to get loaded in other machines causing the above error. This is due to the library dependencies that gets created when building DLL.

Reason
        This is due to the library dependencies as said above. Microsoft Visual Studio is highly sensitive on the Build configuration, due to which the generated DLL's dependencies may get affected. For example, the "sample.dll" built may have dependencies on some "XYZ.dll version a.b.c". This "XYZ.dll version a.b.c" may exist in multiple version on a machine due to various reasons, such as Visual Studio version installed, Internet explorer installed etc. Its responsibility of the System, or Application to find the dependencies correct version and load the required DLL. This responsibility factor is decided based on the RT_MANIFEST present in DLL generated.

Solution
Sol -1.There are various tools available for checking the dll dependencies. "Dependency Walker" is one of the common tool used to check such dependencies. Once you find the dll dependencies, try to copy these missing dll's in respective folders based on the dll category such as (System dll, application dll's). If all the dll's exist go for the next solution.

Sol -2. Build the DLL using "release" mode instead of "Debug". This avoids the Visual C++ Redistribution package DLL dependencies being getting added in the RT_MANIFEST. If still unable to load the library in java, go for the final solution below.

Sol -3. The Project Properties->Code Generation -> Runtime Library option play a crucial role in dll creation. Based on this many dependencies gets added or removed such as MSVCR80D.DLL, MSVCP80D.DLL, IESHIMS.DLL. One solution would be build the DLL as Multi threaded instead of Multi thread DLL as shown