Wednesday, November 6, 2013

Navigation view scrollbar is not visible in Eclipse Mac OS but visible in windows OS

Have you ever encountered an issue with scrollbars in eclipse, especially in navigation views or application views, which is visible in windows or but does not appear in Mac OS system.

Then reason could be with the Mac system preferences. Please follow below steps to enable the scrollbar in Mac.

1. Go to Mac Menu( Apple icon), you will find this in the top left corner of the system.
2. Click on 'System Preferences'.
3. Click on 'General' item from the ‘Personal’ section.
4. You can find 'Show scroll bars’ section.
5. Select ' Always' radio button.

This will enable the scrollbar in the navigation view, without this option also scrollbar will be there, just that you will not be able to realize that there is a scrollbar unless you start dragging in navigation view.


Please find the screenshot for system preferences configuration.


New to Mac - Print screen shorcuts

Command+Shift+3: Takes a screenshot of the full screen (or screens if multiple monitors), and save it as a file to the desktop

Command+Shift+4: Brings up a selection box so you can specify an area to take a screenshot of, then save it as a file to the desktop

Command+Shift+4, then spacebar, then click a window: Takes a screenshot of a window only and saves it as a file to the deskto

Tuesday, November 5, 2013

Java was started by returned exit code=1

Possible causes include:  The eclipse.ini configuration, wrong JAVA version, incorrect or corrupted JAVA installation and incompatibility between an eclipse plugin and the JAVA version.

Following are some links that list some of the causes and possible solutions for this error:

1.  Add the command -XX:-UseCompressedOops  at the end of the eclipse.ini file.  See the following link where this action is reported to resolve this issue:

http://www.eclipse.org/forums/index.php/m/653614/#msg_653614

2.  Remove and reinstall both the JAVA JDK and JRE.  See the following link where this action is reported to resolve this issue:

http://anmolanand.wordpress.com/2011/06/19/eclipse-java-was-started-but-returned-exit-code-1/

3.  Check to make sure that a JAVA update did not cause the error.  See the following links where a JAVA update is reported to have caused the issue:

http://www.coderanch.com/t/503269/vc/Eclipse-start-but-return-exit

http://stackoverflow.com/questions/4587518/eclipse-error-on-startup-windows-7

4.  Some eclipse plugin may not be compatible with the installed JAVA version.  See the following link where this situation is reported to have caused the issue:

http://www.eclipse.org/forums/index.php/t/266786/

Java/Eclipse Source code download

Any jar files source code
http://grepcode.com/

Eclipse related: SWT, JFace, etc..
http://archive.eclipse.org/eclipse/downloads/

Any Java related jars:
http://www.java2s.com/

Wednesday, October 30, 2013

Reading windows registry using Runtime.getRuntime().exec(..) command

In my previous post @ http://exploreeclipse.blogspot.in/2013/10/reading-windows-registry-values-using.html , I was talked about reading windows registry using JNA library. But Java also provides support to read the windows registry through Java Runtime command execution.

In this article will focus on how to read win registry using Runtime.getRuntime().exec(..) command.

Basically you need these 3 parameters to hit the registry.
1. What is the Location ?
2. What is the registry key type ?
3. What is the key you want to read ?

Example:
I want to read the following parameters.
Location = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Android SDK Tools";
Key = "Path";
Registry Type = "REG_SZ"

Above parameters basically tells, what is the Andriod SDK Tools 'Path' directory ? That is what i want to figure it out.

Below piece of code, which will help you to get the Andriod sdk tools path directory.


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class WindowsRegistryReader {

public static void main(String[] args) {

String location = "HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Android SDK Tools";
String key = "Path";
String regType = "REG_SZ";

try {
String value = read(location, key, regType);
System.out.println("==========Output=================");
System.out.println("location: " + location);
System.out.println("Type: " + regType);
System.out.println("key: " + key + "  value: " + value);
System.out.println("=================================");

} catch (IOException e) {
e.printStackTrace();
}
}

public static String read(String location, String name, String regType) throws IOException {

Process p = Runtime.getRuntime().exec("reg QUERY \"" + location + "\" /v \"" + name + "\"");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String out = "";
while ((out = in.readLine()) != null) {
if (out.matches("(.*)\\s+REG_(.*)")) {
break;
}
}
in.close();
if (out != null) {
int indexOf = out.indexOf(regType);
if (indexOf != -1) {
String value = out.substring(indexOf + regType.length()).trim();
return value;
}
}
return null;
}
}


Output:
==========Output=================
location: HKEY_LOCAL_MACHINE\Software\Wow6432Node\Android SDK Tools
Type: REG_SZ
key: Path  value: C:\Program Files (x86)\Android\android-sdk

=================================

Various Windows registry type values can be found @ http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx

Monday, October 28, 2013

Programmatically gettting Eclipse installation path directory

You might have some properties file or some other file at your eclipse home directory and you want to read that, for this you required a eclipse home directory path.

Below is the piece of code which helps you to get that.

public class EclipseLocation {

@SuppressWarnings("unchecked")
public static <T> T getService(Class<T> clazz, String filter) {
BundleContext context = MyPlugin.getDefault().getBundle().getBundleContext();
ServiceTracker tracker = null;
try {
tracker = new ServiceTracker(context, context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + clazz.getName() //$NON-NLS-1$ //$NON-NLS-2$
+ ")" + filter + ")"), null); //$NON-NLS-1$ //$NON-NLS-2$
tracker.open();
return (T) tracker.getService();
} catch (InvalidSyntaxException e) {
return null;
} finally {
if (tracker != null)
tracker.close();
}
}
}

Invocation:
EclipseLocation.getService(Location.class, Location.INSTALL_FILTER)


Output:
C:/myInstallations/Eclipse



You can also achieve the same thing using the system property 'eclipse.launcher'.

//this returns C:/myInstallations/Eclipse/eclipse.exe
String launcherLocation = System.getProperty("eclipse.launcher");  //

if (launcherLocation != null ) {
File launcherLocationFile = new File(launcherLocation);

//get the parent of eclipse.exe file->C:/myInstallations/Eclipse
String eclipseDir = launcherLocationFile.getParent();

//your piece of logical code resides here
                   }



Hope this helps.

Thursday, October 24, 2013

Reading Windows registry values using java


This can be done using JNA(Java Native Access) library.

Use this link to download @ https://github.com/twall/jna#readme

Required jars: 

Piece of code to test:

Here I am trying to read Android installation path from windows registry.


public static void main(String[] args) {

try {
Map<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Android SDK Tools");
for (String value : values.keySet()) {
System.out.println(value + "   " + values.get(value));

}
} catch (Exception e) {
e.printStackTrace();
}

}

public static void main(String[] args) {

try {
Map<String, Object> values = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Android SDK Tools");
for (String value : values.keySet()) {
System.out.println(value + "   " + values.get(value));

}
} catch (Exception e) {
e.printStackTrace();
}

}


Output:
Path   D:\Work\Android\adt-bundle-windows-x86-20130522\adt-bundle-windows-x86-20130522