Categories
discuss

Automatically opening completion window in Eclipse

I am new to Eclipse and I want to know if it’s possible to have the completion window open up automatically while I type (Visual Studio style) and not by clicking Ctrl + Space?

Answer

It is possible. You can simply write: .abcdefghijklmnopqrstuvwxyz in Auto activation triggers for Java field, under Preferences > Java > Editor > Content Assist.

While writing Java code, after the dot . the window opens automatically after a configurable amount of time (default is 200 ms.)

In general, what you can do is add an auto activation trigger, for example _, so when you want the windows to popup, you type and delete that character (althought I don’t think that’s better than CTRL + SPACE).

Categories
discuss

Extract and load DLL from JAR

My Java application uses a DLL library. How can I get it work from the JAR file?

The DLL is in the project’s sources folder. I have to include it in my JAR, extract it at runtime (in the same directory of the jar) and load it.

Answer

You need to put dll in your library path (recommended ) before you try to load it. so that you will have to extract it from jar and copy it into lib path .

private void loadLib(String path, String name) {
  name = System.mapLibraryName(name); // extends name with .dll, .so or .dylib
  InputStream inputStream = null;
  OutputStream outputStream = null;
  try {
    inputStream = getClass().getResourceAsStream("/" + path + name);
    File fileOut = new File("your lib path");
    outputStream = new FileOutputStream(fileOut);
    IOUtils.copy(inputStream, outputStream);

    System.load(fileOut.toString());//loading goes here
  } catch (Exception e) {
    //handle
  } finally {
    if (inputStream != null) {
      try {
        inputStream.close();
      } catch (IOException e) {
        //log
      }
    }
    if (outputStream != null) {
      try {
        outputStream.close();
      } catch (IOException e) {
        //log
      }
    }
  }

}

Note: ACWrapper is the class holding the static method

Categories
discuss

Edit JavaScript blocks of web page… live

I know you can use Firebug in the DOM view to edit JavaScript variables BUT… is there a way I can use (anything else) to edit live JavaScript that is embedded in a HTML page?

Like this kind that is in a .html page:

<script type="text/javascript>
// code here
</script>

Thanks.

Answer

bookmarklets

From the Wikipedia entry

A bookmarklet is an applet, a small computer application, stored as the URL of a bookmark in a web browser or as a hyperlink on a web page. The term is a portmanteau of the terms bookmark and applet. Whether bookmarklet utilities are stored as bookmarks or hyperlinks, they are designed to add one-click functionality to a browser or web page. When clicked, a bookmarklet performs some function, one of a wide variety such as a search query or data extraction. Usually the applet is a JavaScript program.

And as a related note not trying to spam or anything I created a bookmarklet generator to help me create bookmarklets easier.

Categories
discuss

Is Java SE still GPL? [closed]

Is Java SE still open source? Can Oracle change the licensing after its been dedicated to GPL?

However, on the Oracle Java FAQ it states that it is Binary Code Licence.

“Sun begins releasing Java under the GPL”

Free Software Foundation

“The adoption of the GPL v2 license for Sun’s Java SE (JDK) and Java ME implementations, and adding this license to Sun’s Java EE implementation.”

James Gosling

Yet on the Java FAQ page it states:

  1. Q: Is Java technology free? Where can I get information on licensing?
    A: Java SE continues to be available under the Sun Binary Code
    License (BCL) with no additional cost
    for its use in general purpose
    computing. The Java technology support
    and EOL roadmap provides more
    information. Java for Business
    binaries are provided under separate
    licensing terms. A summary of the
    Java SE and Java for Business
    licensing terms is provided below

Oracle

If they can change the license does it retroactively effect all released source?

Answer

Is Java SE still open source?

OpenJDK is the GPL’ed “edition” of Java SE. Oracle (as did Sun), provided their own release, under a different license, and other more or less small differences.

Can Oracle change the licensing after
its been dedicated to GPL?

Yes, they can change the license of the pieces in OpenJDK they own the copyright of (likely the better part of it), but not retroactivly. The GPL’ed versions that’s out now can’t be changed.

Categories
discuss

@Override annotation error (android prefs)

When I was trying to use this code to enable preferences into my app

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class Preferences extends PreferenceActivity {

private RadioButton btn01;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    btn01 = (RadioButton)findViewById(R.id.RadioButton01);
    Preference customPref = (Preference) findPreference("customPref");

    customPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){

        public boolean onPreferenceClick(Preference preference) {
            Toast.makeText(getBaseContext(),"The Custom Preference Has Been Clicked",Toast.LENGTH_LONG).show();
            SharedPreferences customSharedPreference = getSharedPreferences("myCutomSharedPrefs", Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = customSharedPreference.edit();
            editor.putString("myCustomPref","The preference has been clicked");
            editor.commit();
            return true;
        }


        public void CheckBox() {
            final CheckBox ThisCheckBox = (CheckBox) findViewById (R.id.checkboxPref);
            ThisCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
                @Override
               public void onCheckedChanged(CompoundButton compoundButton,boolean test) {
                    if (ThisCheckBox.isChecked()){ 
                        btn01.setVisibility(0);
                    } else {
                        btn01.setVisibility(2);
                    }
                }
            });
        };
    });
}
}

An error is generated on this line

 public void onCheckedChanged(CompoundButton compoundButton,boolean test) {

saying:

Multiple markers at this line
- The method onCheckedChanged(CompoundButton, boolean) of type new 
 CompoundButton.OnCheckedChangeListener(){} must override a superclass method
- implements 
 android.widget.CompoundButton.OnCheckedChangeListener.onCheckedChanged 

If i remove the @Override annotation then the code doesn’t work and a warning tells me that the that part of the code is not used locally.

Having run this past someone and baffling them I was wondering if you could help?

Are there any common scenarios that causes this error?

I thought it might be my project set up

Thanks

Answer

It’s an implementation thing. In Java 5 vs Java 6 they changed whether you could use “Override” with an interface (since Override seems to imply that you are overriding some sort of default behavior, which you are not doing with an interface!). If you so desire, you can search in the Eclipse preferences and change it from a compilation error to a compilation warning. You code inside of the CheckBox() function looks fine to me.

However, you are never calling the CheckBox function, so that’s where the ‘not used locally’ error is coming from. Were you meaning to call that function from within the OnPreferenceClick method?

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..