Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Ekster posted:

I've been trying to debug using IntelliJ but I can't seem to run/debug classes that I've already compiled from the command line without having to create a special project for it. In Visual Studio I could just open the executable and it would automatically fetch all the debug info so I didn't have to setup anything. How can I do the same thing in IntelliJ or possibly Eclipse/Netbeans?


I'm not sure if there's a way to do that locally without building and running from the IDE, but at work we use the remote debugger (all 3 should have this.) For IntelliJ, do Run > Edit Configurations..., hit the + and choose a new Remote. The dialog will show you the argument you need to supply to java in the command line to get your program to allow remote debugging (you'll probably want the first one.) Save this, and start your program then hit Debug and as long as the ports match they should connect up.



You can change the suspend to y if you want the JVM to wait for you to connect before executing your program, but by default it'll start up and you can just connect whenever.

Then you can just open up the folder with your source files as if it's a project and hopefully breakpoints should work (I tried it with an old project from school here:)

carry on then fucked around with this message at 00:59 on Sep 1, 2015

Adbot
ADBOT LOVES YOU

hooah
Feb 6, 2006
WTF?
Do you have a specific reason to be divorcing writing and debugging into separate workflows? It seems it would be a lot easier to just write and debug in the IDE.

Ekster
Jul 18, 2013

carry on then posted:

Super helpful writeup.

Thanks, I'll try it out.

hooah posted:

Do you have a specific reason to be divorcing writing and debugging into separate workflows? It seems it would be a lot easier to just write and debug in the IDE.

I like doing all my coding in the same text editor (Sublime) regardless of language. I also dislike having to jump through IDE hoops (read: project/link/compile settings) when it's often easier to just do it from the command line through a batch file. Like I said earlier I'm still fairly new to programming so I'm still testing out what setups I like and such. This is what I learned and liked the most when coding in C/C++ so I'm trying to do the same thing with Java if reasonably possible.

Volguus
Mar 3, 2009

Ekster posted:

I like doing all my coding in the same text editor (Sublime) regardless of language. I also dislike having to jump through IDE hoops (read: project/link/compile settings) when it's often easier to just do it from the command line through a batch file. Like I said earlier I'm still fairly new to programming so I'm still testing out what setups I like and such. This is what I learned and liked the most when coding in C/C++ so I'm trying to do the same thing with Java if reasonably possible.

Even with C++, doing everything in the same IDE helps a lot. Compile/debug cycle is greatly reduced on a moderately sized project. On very simple ones ... I guess it doesn't matter really. I can't say I understand the love for sublime (good editor, nothing against it), but there's a reason why majority of people work in an IDE: it simply makes you more productive. Except IntelliJ, that thing does everything in its power to cut productivity to zero. You wanna write code? Not on my watch...

hooah
Feb 6, 2006
WTF?
Aren't PyCharm and Android Studio both forks of IntelliJ? I've enjoyed them well enough, although my small Android app's the biggest thing I've done in either of them.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

hooah posted:

Aren't PyCharm and Android Studio both forks of IntelliJ?

Yes

That said I still prefer Eclipse

Hughlander
May 11, 2005

hooah posted:

Aren't PyCharm and Android Studio both forks of IntelliJ? I've enjoyed them well enough, although my small Android app's the biggest thing I've done in either of them.

And AppCode and RubyMine and CLion... Best of breed IDE with same interface.

Yaoi Gagarin
Feb 20, 2014

Hughlander posted:

And AppCode and RubyMine and CLion... Best of breed IDE with same interface.

Anecdotal, but I had a devil of a time getting CLion to work with the one project I used it for*, and it wasn't even particularly big. IntelliJ seemed okay for working with Java though.

*Granted, I was running it on my laptop, which doesn't have a very good CPU. Perhaps the best advice, especially for IDEs that are themselves running in the JVM, is to make sure you've got some good hardware to power all the code completion and static analysis and whatnot.

edit: And C++ compilation is more difficult than Java compilation AFAIK, so that probably contributed.

baquerd
Jul 2, 2007

by FactsAreUseless

Volguus posted:

Oh, like what everyone else had since forever?

Have you actually seen how the inline debugging is implemented? I haven't seen Eclipse with anything quite like it, though it's not a major thing. I'm not sure why you seem to hate IntelliJ, I've found it way more useful than Eclipse.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Volguus posted:

Even with C++, doing everything in the same IDE helps a lot. Compile/debug cycle is greatly reduced on a moderately sized project. On very simple ones ... I guess it doesn't matter really. I can't say I understand the love for sublime (good editor, nothing against it), but there's a reason why majority of people work in an IDE: it simply makes you more productive. Except IntelliJ, that thing does everything in its power to cut productivity to zero. You wanna write code? Not on my watch...

IntelliJ is beautiful, and you continue to be wrong about everything.

Except for that IDE stuff. Seriously, I'd say that 75-90% of the characters in my code are the result of hammering on CTRL+Space, and the IDE guessing correctly. Java is conventionally verbose, and this is a good thing - it makes your code readable, and therefore far more maintainable than janky-assed C where your variables are i, ii, j, k, pk, n, and c. Still, if you're going to have an AuthenticationServiceFactory named authenticationServiceFactory, there's no reason why you should have to press 50 buttons; a good IDE will cut that down to six or so.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

I'd say something that's overlooked about IDEs is what they bring to code reading. The ability to jump straight to a class definition, find all the usages of a given variable, or immediately construct a call hierachy for a method are indispensible in getting into 100,000+ line projects and following the piece you're interested in, especially when you can then jump right into a debugging session.

loinburger
Jul 10, 2004
Sweet Sauce Jones
I had a co-worker who was senior to me who was in the Real Programmers Only Use Notepad (or TextEdit or whatever) camp; this meant that he reassigned all of his bug tickets to me since I was willing to debase myself and use a debugger.

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

loinburger posted:

I had a co-worker who was senior to me who was in the Real Programmers Only Use Notepad (or TextEdit or whatever) camp; this meant that he reassigned all of his bug tickets to me since I was willing to debase myself and use a debugger.

Someone should have told him about jdb, I guess.

Volguus
Mar 3, 2009

Gravity Pike posted:

IntelliJ is beautiful, and you continue to be wrong about everything.

Except for that IDE stuff. Seriously, I'd say that 75-90% of the characters in my code are the result of hammering on CTRL+Space, and the IDE guessing correctly. Java is conventionally verbose, and this is a good thing - it makes your code readable, and therefore far more maintainable than janky-assed C where your variables are i, ii, j, k, pk, n, and c. Still, if you're going to have an AuthenticationServiceFactory named authenticationServiceFactory, there's no reason why you should have to press 50 buttons; a good IDE will cut that down to six or so.

Haha, you wish. It is actually amazing how wrong IntelliJ gets CTRL+Space most of the time, when it even wants to work. Sometimes it just stares like a deer in the headlights with no loving answer.
Yes, I did not import java.util.* . Yes, I used ArrayList a second ago. Now I wanna try LinkedList. Yes, you should be able to provide me with the suggestion after 2-3 characters (typing "lin") not make me type the whole drat thing, only afterwards to offer to import it.
Sigh ....

Max Facetime
Apr 18, 2009

Janitor Prime posted:

The debugging features in all 3 are very similar, try each of them and whichever UI doesn't disgust you wins

One useful feature that only Eclipse seems to have (I'd love to be proven wrong on this) is Drop to Frame.

Drop to Frame can be used to restart execution from the start of the current method or any other method in the thread's call stack. This is most useful if the arguments for the method haven't been mutated and it hasn't changed any global state. Then whatever error condition happened while executing that method will be happening exactly the same way, again. So basically time-travel for functional code.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Volguus posted:

Haha, you wish. It is actually amazing how wrong IntelliJ gets CTRL+Space most of the time, when it even wants to work. Sometimes it just stares like a deer in the headlights with no loving answer.
Yes, I did not import java.util.* . Yes, I used ArrayList a second ago. Now I wanna try LinkedList. Yes, you should be able to provide me with the suggestion after 2-3 characters (typing "lin") not make me type the whole drat thing, only afterwards to offer to import it.
Sigh ....

This works literally 100% of the time for me (and probably everyone else too) in Studio, maybe you should try un-loving your configuration.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Max Facetime posted:

One useful feature that only Eclipse seems to have (I'd love to be proven wrong on this) is Drop to Frame.

Drop to Frame can be used to restart execution from the start of the current method or any other method in the thread's call stack. This is most useful if the arguments for the method haven't been mutated and it hasn't changed any global state. Then whatever error condition happened while executing that method will be happening exactly the same way, again. So basically time-travel for functional code.

:monocle:

Eclipse has this? Since when? I've always wanted this for Java debugging!

One area where I find eclipse to shine over IntelliJ is their static analysis to build the class models for my project. In particular, the "call hierarchy" and "type hierarchy" commands are absolutely invaluable and have only weak imitation in IntelliJ in the form of the "find references" command.

Volguus
Mar 3, 2009

Jabor posted:

This works literally 100% of the time for me (and probably everyone else too) in Studio, maybe you should try un-loving your configuration.

My configuration is pristine, except the checkbox: "Case insensitive autocompletion" , which I hoped would fix this little issue. It didn't. This and other bazillion little things like it make IntelliJ a loving nightmare for me and everyone else i know. Except, of course, 5 people on the internet that are loud and few.
Why am I so angry at it? Because some smartass in the organization (very high up the chain, lives in the stratosphere) decided that it'll be a good idea to impose intellij on people (if we're paying for licenses then you better use them). Every developer I've seen and talked with is still furious at the decision. Some use it angrily, some just use eclipse, some went ballistic and started using vim and other crazy editors.

I really did want to give it a chance. I tried. The plugins for the enterprise edition (maven, git, spring, html, javascript, jee, etc.) are on par with netbeans' and eclipse's . The core of the IDE , the editor, the basic functions, a disaster.

baquerd
Jul 2, 2007

by FactsAreUseless

Volguus posted:

My configuration is pristine, except the checkbox: "Case insensitive autocompletion" , which I hoped would fix this little issue. It didn't. This and other bazillion little things like it make IntelliJ a loving nightmare for me and everyone else i know. Except, of course, 5 people on the internet that are loud and few.

That's bizarre. There are certainly some few occasions where it doesn't auto complete exactly how I'd like, but 99% of the time is spot on and together with live templates, it's rare I have to type complete words.

I should mention I'm in a mixed IDE environment, and right now, given free choice, we're about 60% IntelliJ, 35% eclipse and 5% NetBeans.

baquerd fucked around with this message at 15:54 on Sep 1, 2015

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Are you sure you haven't, for example, got anything in the "exclude from auto-import" list in the settings? (One of the quibbles I do have with IntelliJ is that it's a bit too easy to add things to that list, e.g. by fat-fingering something while the autocomplete dialog is up.)

TheresaJayne
Jul 1, 2011

Volguus posted:

My configuration is pristine, except the checkbox: "Case insensitive autocompletion" , which I hoped would fix this little issue. It didn't. This and other bazillion little things like it make IntelliJ a loving nightmare for me and everyone else i know. Except, of course, 5 people on the internet that are loud and few.
Why am I so angry at it? Because some smartass in the organization (very high up the chain, lives in the stratosphere) decided that it'll be a good idea to impose intellij on people (if we're paying for licenses then you better use them). Every developer I've seen and talked with is still furious at the decision. Some use it angrily, some just use eclipse, some went ballistic and started using vim and other crazy editors.

I really did want to give it a chance. I tried. The plugins for the enterprise edition (maven, git, spring, html, javascript, jee, etc.) are on par with netbeans' and eclipse's . The core of the IDE , the editor, the basic functions, a disaster.

Intellij is good, The main thing though is its designed around TDD so the autocomplete is designed to work best when you are doing that. ie

List<MyClass> myList = new Arr<CTRL-SPACE> will provide ArrayList as well as even ArrayList<MyClass>();

I am forced to use Eclipse at work :( and I suddenly found i am trying to do Ctrl-Shift-G instead of Alt-F7 in intellij at home.

Also Eclipse has the same as Ctrl-Space but its harder to do CTRL - 1

Each to their own.

Volguus
Mar 3, 2009

TheresaJayne posted:

Intellij is good, The main thing though is its designed around TDD so the autocomplete is designed to work best when you are doing that. ie

List<MyClass> myList = new Arr<CTRL-SPACE> will provide ArrayList as well as even ArrayList<MyClass>();

I am forced to use Eclipse at work :( and I suddenly found i am trying to do Ctrl-Shift-G instead of Alt-F7 in intellij at home.

Also Eclipse has the same as Ctrl-Space but its harder to do CTRL - 1

Each to their own.

In my example, thats exactly what I was doing:
wanted to go from:
List<MyClass> myList = new ArrayList<>();
to:
List<MyClass> myList = new lin<CTRL+SPACE> and nothing. just a blank stare.

Regarding the eclipse comment .... IntelliJ doesn't even have ctrl+1 (i mean, it may have it somewhere in the settings, but its not enabled by default).
In eclipse I can do:

int var = someNewMethodThatDoesntExistYet("some string param");

And in Eclipse if i press ctrl+1 will offer to make that method for me with the correct return type and params.

In IntelliJ they have a button at the beginning of the line that provides a dropdown list to make that method, but that requires to reach for the mouse get to the button, click it, select the option, etc., when i already have both my hands on the keyboard and ctrl+1 is really drat handy. As I said, the example given is just the latest one that happened few days ago, and it's really dumb behaviour. There are a bazillion little things that it does (or doesn't do) that make me go WTF every 5 minutes, then i drop what im doing, google for the problem and either find that IntelliJ cannot do that (yet, but it's coming we promise) (crazy how often I see that) or that it does it but in some other convoluted and mind boggling way. Another WTF gets uttered.

And people here recommend IntelliJ to newcomers like its the second coming. And then these newcomers come to think that all the crazy things IntelliJ does are normal. That this is how an IDE should behave. And it just simply isn't. Way too many things it does are simply not normal or straightforward. Their base is broken. I've tried IntelliJ, WebStorm and CLion and they're simply IDEs built upon a broken foundation (and CLion does C++ parsing in Java .... sigh) . Resharper is good, but that's most likely because the foundation it's built on is solid.

Zorro KingOfEngland
May 7, 2008

Does Eclipse have anything like IntelliJ's Intention Actions autocomplete (alt + enter)? I find myself relying on it a lot and when I used Eclipse I don't think they had anything like it.

That being said I don't think there's a huge difference between the two IDE's, you should be free to use whatever works for you. Other than getting used to the keyboard shortcuts again I wouldn't have a problem going back to Eclipse if I had to.

EDIT: upon Googling, Eclipse's control + 1 looks very similar to IntelliJ's alt + enter.

For reference, here's what that IntelliJ's alt+enter does with that example you had:


after you hit enter, it takes you to the code it added and lets you pick the return type from a list of acceptable types based on the variable you are setting


then it takes you to each parameter name so you can rename them without moving your cursor directly


then it takes you to the method body where it's helpfully auto-inserted a default return statement so you don't have a compiler error. That return statement is highlighted so if you type it immediately erases the default return statement without any additional keystrokes.

Zorro KingOfEngland fucked around with this message at 18:55 on Sep 1, 2015

TheresaJayne
Jul 1, 2011

Volguus posted:

In my example, thats exactly what I was doing:
wanted to go from:
List<MyClass> myList = new ArrayList<>();
to:
List<MyClass> myList = new lin<CTRL+SPACE> and nothing. just a blank stare.

Regarding the eclipse comment .... IntelliJ doesn't even have ctrl+1 (i mean, it may have it somewhere in the settings, but its not enabled by default).
In eclipse I can do:

int var = someNewMethodThatDoesntExistYet("some string param");

And in Eclipse if i press ctrl+1 will offer to make that method for me with the correct return type and params.

In IntelliJ they have a button at the beginning of the line that provides a dropdown list to make that method, but that requires to reach for the mouse get to the button, click it, select the option, etc., when i already have both my hands on the keyboard and ctrl+1 is really drat handy. As I said, the example given is just the latest one that happened few days ago, and it's really dumb behaviour. There are a bazillion little things that it does (or doesn't do) that make me go WTF every 5 minutes, then i drop what im doing, google for the problem and either find that IntelliJ cannot do that (yet, but it's coming we promise) (crazy how often I see that) or that it does it but in some other convoluted and mind boggling way. Another WTF gets uttered.

And people here recommend IntelliJ to newcomers like its the second coming. And then these newcomers come to think that all the crazy things IntelliJ does are normal. That this is how an IDE should behave. And it just simply isn't. Way too many things it does are simply not normal or straightforward. Their base is broken. I've tried IntelliJ, WebStorm and CLion and they're simply IDEs built upon a broken foundation (and CLion does C++ parsing in Java .... sigh) . Resharper is good, but that's most likely because the foundation it's built on is solid.

Resharper and Intellij have the same core.

Ctrl-Space is the same as Ctrl-1

also you can select code right click, refactor.. Extract Method, POW done, or you can learn the correct keymap. That is where the power is, Every command can be Key Mapped in intellij.
also there are short codes you can use.
Ctrl-Space - Basic Code Completion - any matching

Ctrl-Shift-Space - Smart Code completion - filtered on type

Ctrl-Shift-Enter - Complete Statement

Alt-Insert Generate Code - Getters/Setters, Constructors hashCode/Equals toString

Ctrl-Alt-T Surround With (if-else, try-catch, for, synchronized etc)

Ctrl-Alt-O Optimise imports

Ctrl-Alt-L Reformat code

Alt-F7 - Find usages

Ctrl-N Goto Class

Simples.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Volguus posted:

In my example, thats exactly what I was doing:
wanted to go from:
List<MyClass> myList = new ArrayList<>();
to:
List<MyClass> myList = new lin<CTRL+SPACE> and nothing. just a blank stare.

Yeah I get this too, but typing Lin makes it work. "Case sensitive completion" looks to be turned on by default in the settings, I turned that off and then it works (or Ctrl+Shift+Space for kaboom mode)

Just noticed Alt+/ is in the Code Completion menu, that was magical in Eclipse. How long's that been there?

Volguus posted:

In eclipse I can do:

int var = someNewMethodThatDoesntExistYet("some string param");

And in Eclipse if i press ctrl+1 will offer to make that method for me with the correct return type and params.

I did this and the method name was highlighted in red, then Alt+Return gives the menu thing with 'create a method' highlighted, so you can just hit Return and it creates the method template. Then you can hit Return to accept all the types and names and whatever or adjust them as you go.

I hated IntelliJ after switching from Eclipse, but then I came to really like it, especially now it has a decent Git plugin. It does have some annoying quirks, especially when things like Alt+Return aren't working on the right context for whatever reason, but mostly it's been a case of finding out how to do things and getting familiar with it

Necc0
Jun 30, 2005

by exmarx
Broken Cake
I'm asking here because Google is trash and only giving me articles written 15 years ago

What's the generally accepted library to use for downloading any https (ssl) pages? Google is only linking me to decade+ articles which tell me to use JSSE which has been mothballed for a long time now.

edit: nvm of course I come up with a query Google understands after I post here :downs:

Necc0 fucked around with this message at 21:33 on Sep 1, 2015

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Necc0 posted:

I'm asking here because Google is trash and only giving me articles written 15 years ago

What's the generally accepted library to use for downloading any https (ssl) pages? Google is only linking me to decade+ articles which tell me to use JSSE which has been mothballed for a long time now.

edit: nvm of course I come up with a query Google understands after I post here :downs:

Probably HttpComponents. Be careful not to mix it up with Apache Commons HttpClient; HttpComponents is the successor to that project, and it's easy to import the wrong thing and be stuck on a decade-old library.

Imazul
Sep 3, 2006

This was actually a lot more bearable than most of you made it out to be.

loinburger posted:

I'm using Spring Retry for some database operations. On a SQLRecoverableException I retry three times and then I quit and log the exception; on a SQLTransientException I retry indefinitely (the user has the option of cancelling the operation); on any other exception I quit and log it. I'm using exponential backoff with a starting wait of 100ms and a maximum wait of 30,000ms.
code:
public static RetryTemplate databaseTemplate() {
    RetryTemplate template = new RetryTemplate();
    Map<Class<? extends Throwable>, RetryPolicy> policyMap = new HashMap<>();
    SimpleRetryPolicy recoverablePolicy = new SimpleRetryPolicy();
    recoverablePolicy.setMaxAttempts(3);
    policyMap.put(Exception.class, new NeverRetryPolicy());
    policyMap.put(SQLRecoverableException.class, recoverablePolicy);
    policyMap.put(SQLTransientException.class, new AlwaysRetryPolicy());
    ExceptionClassifierRetryPolicy retryPolicy = new ExceptionClassifierRetryPolicy();
    retryPolicy.setPolicyMap(policyMap);
    template.setRetryPolicy(retryPolicy);
    template.setBackOffPolicy(exponentialPolicy(100, 30 * 1000, 2.0));
    return template;
}
The issue I'm having is that ideally I'd like to always retry SQLRecoverableExceptions after 100ms and only apply exponential backoff to SQLTransientExceptions. I could do this with a nested retry block, but I'd prefer to just build it into the backoff policy so that I only need one template/block. Anybody have any experience with this?

I don't think there is an easy way to do it directly through the template. One thing you can always do is change the back off policy anytime wtihout affecting existing process so if you are really motivated you could build a quick AOP block to automatically change it based on exception type. At that point though you are almost better off doing it in the function.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

TheresaJayne posted:

Ctrl-Alt-L Reformat code

The same key combo to lock the screen on Ubuntu.

:negative:

geeves
Sep 16, 2004

Volmarias posted:

The same key combo to lock the screen on Ubuntu.

:negative:

You can change it in the keymap to whatever combo you'd prefer.

Necc0
Jun 30, 2005

by exmarx
Broken Cake

Gravity Pike posted:

Probably HttpComponents. Be careful not to mix it up with Apache Commons HttpClient; HttpComponents is the successor to that project, and it's easy to import the wrong thing and be stuck on a decade-old library.

Follow-up: Does anyone know of a good up-to-date tutorial walking through getting this working from end to end? I'm running into a lot of trouble with the keytool trying to import the certificate I need and I have no idea where I went off the rails. Want to wipe and start over from scratch. Unfortunately like I said before google is refusing to give me anything that was written in the past five years.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Any certificate fuckrey should be done using Portecle so that you have an easier interface into what's going on. As for the http client the site has a bunch of useful examples on how to use it, but I'm not aware of any recent tutorials for it.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I started playing with a new project and have been using JavaFX image, converting it to a matrix, and fiddling with it. It looks like AWT has a bunch of helpful features and has the advantage of not needing to spin up a GUI to load an image. I don't want to get stuck in 1997, but man, JavaFX images... Is it bad form to use AWT? Is there a library which has supplanted them?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Jo posted:

I started playing with a new project and have been using JavaFX image, converting it to a matrix, and fiddling with it. It looks like AWT has a bunch of helpful features and has the advantage of not needing to spin up a GUI to load an image. I don't want to get stuck in 1997, but man, JavaFX images... Is it bad form to use AWT? Is there a library which has supplanted them?

You could use AWT, but JavaFX should be able to do what AWT can too, and mixing both could be unnecessarily messy. There's almost assuredly a way to do what you're doing in AWT using JavaFX, and you'd probably be better off just figuring out how to do that by reading more JavaFX documentation or whatever.

Like yeah AWT was supplanted... by JavaFX. Also SWT, QT, etc. but w/e.

What about needing a GUI to load an image?
Can't you just
Image image = new Image(Path); ?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

You could use AWT, but JavaFX should be able to do what AWT can too, and mixing both could be unnecessarily messy. There's almost assuredly a way to do what you're doing in AWT using JavaFX, and you'd probably be better off just figuring out how to do that by reading more JavaFX documentation or whatever.

Like yeah AWT was supplanted... by JavaFX. Also SWT, QT, etc. but w/e.

What about needing a GUI to load an image?
Can't you just
Image image = new Image(Path); ?

No, unfortunately. If you don't do launch(args) to start up the GUI component of the application, JavaFX won't allow you to use Images. That wouldn't be a problem if I were making a GUI application only, but I'm doing a dual-mode CLI/GUI app. Plus, Image doesn't have ConvolveOps like AWT and is missing a ton of features, like resizing. (You need to make an ImageView, render to an image view, then take a screenshot of the image view. Really.)

Here's the stack trace when I run it as CLI:

code:
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.IllegalStateException: Not on FX application thread; currentThread = main
	at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:204)
	at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:438)
	at javafx.scene.Node.snapshot(Node.java:1907)
	at com.josephcatrambone.sharpcloud.ImageTools.FXImageToMatrix(ImageTools.java:41)
	at com.josephcatrambone.sharpcloud.ImageTools.ImageFileToMatrix(ImageTools.java:21)
	at com.josephcatrambone.sharpcloud.Main.main(Main.java:63)
	... 11 more
Exception running application com.josephcatrambone.sharpcloud.Main
When I run the same thing inside the start() method on the application after calling launch(), all is well.

Jo fucked around with this message at 19:40 on Sep 3, 2015

Volguus
Mar 3, 2009
Just did a little test and I can load an image just fine (and read a pixel's color) :
code:
    public static void main( String[] args )
    {
       //launch(args);
    	Image img = new Image("file:///home/user/pictures/apod/060314.bmp");
    	Color color = img.getPixelReader().getColor(0, 0);
    	System.out.println("color: "+color.toString());
    	System.exit(0);
    }
With that being said, there is nothing wrong to use Swing and/or AWT classes to read/manipulate images. JavaFX application (an UI one) can host a Swing component if you want to display the image. But if you just want a console application to manipulate an image (like it sounds that you do, saving the image into a matrix and all), use anything that's available in the JDK (not deprecated) and don't worry about it.

And after that, if you really want to display the image in a JavaFX UI application, the javafx Image can load from an InputStream as well (which could be ByteArrayInputStream if you have everything in memory already).

jaete
Jun 21, 2009


Nap Ghost

Gravity Pike posted:

Probably HttpComponents. Be careful not to mix it up with Apache Commons HttpClient; HttpComponents is the successor to that project, and it's easy to import the wrong thing and be stuck on a decade-old library.

Hm, how does this compare to the Ning async HTTP client? Was just talking about which Java HTTP client library is the best, friend says use Ning while colleague swears Ning is the crappiest crap. Dunno.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Volguus posted:

Just did a little test and I can load an image just fine (and read a pixel's color) :
code:
    public static void main( String[] args )
    {
       //launch(args);
    	Image img = new Image("file:///home/user/pictures/apod/060314.bmp");
    	Color color = img.getPixelReader().getColor(0, 0);
    	System.out.println("color: "+color.toString());
    	System.exit(0);
    }
With that being said, there is nothing wrong to use Swing and/or AWT classes to read/manipulate images. JavaFX application (an UI one) can host a Swing component if you want to display the image. But if you just want a console application to manipulate an image (like it sounds that you do, saving the image into a matrix and all), use anything that's available in the JDK (not deprecated) and don't worry about it.

And after that, if you really want to display the image in a JavaFX UI application, the javafx Image can load from an InputStream as well (which could be ByteArrayInputStream if you have everything in memory already).

I'd rather use a consistent set of APIs and use Image everywhere. I'm confused, though, because my code almost exactly matches yours and I get an exception. I've tried two machines, both with the latest JDK, one Windows, one OSX. Same exception.

Are you sure you're importing javafx.scene.image.*; and not the Swing or AWT Image?

EDIT:

Interesting. The following all work:

code:
	public static void main(String[] args) {
		//launch(args);

		Image img = Image("file:" + filename);
	}
code:
	public static void main(String[] args) {
		//launch(args);

		TestImageTools.test("test.png");
	}

	static class TestImageTools {
		public static Image test(String filename) {
			return new Image("file:" + filename);
		}
	}
And they popped up a little 'Java' icon on my toolbar, so they're implicitly spawning a GUI window.

But when I move it into a different file...

code:
public class Main extends Application {
	public static void main(String[] args) {
		//launch(args);

		ImageTools.test("test.png");
	}
}

// Other file.
public class ImageTools {
	public static Image test(String filename) {
		Image img = new Image("file:" + filename);
		return img;
	}
}
THEN it fails.

Jo fucked around with this message at 21:02 on Sep 3, 2015

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Jo posted:

I'd rather use a consistent set of APIs and use Image everywhere. I'm confused, though, because my code almost exactly matches yours and I get an exception. I've tried two machines, both with the latest JDK, one Windows, one OSX. Same exception.

Are you sure you're importing javafx.scene.image.*; and not the Swing or AWT Image?

EDIT:

Interesting. The following all work:

But when I move it into a different file...

public class Main extends Application {

THEN it fails.

Yeah, it should absolutely work without creating all the GUI nonsense exactly like Volguus' example, which is why I was so confused.

The problem has nothing to do with moving it to another class.

The problem is that you're extending Application in the last one, not the others. That's creating a new thread, which then invokes the start method. But you've also got a main method? I'm pretty sure that's wrong, and that's what's causing all your issues. Its a threading problem.

See, look at the exception, it tells you everything:

java.lang.IllegalStateException: Not on FX application thread; currentThread = main

Instead of main() you should put that implementation into public void start(Stage stage) {...} which Application automatically invokes.

Then have a separate static main that constructs your Application, or you can just invoke it as an Application without a main too.

Wait a tic

Jo posted:

When I run the same thing inside the start() method on the application after calling launch(), all is well.

So yeah I guess you're kinda confused on what that happens but you realized already that it did.

Zaphod42 fucked around with this message at 21:30 on Sep 3, 2015

Adbot
ADBOT LOVES YOU

Volguus
Mar 3, 2009

Jo posted:

I'd rather use a consistent set of APIs and use Image everywhere. I'm confused, though, because my code almost exactly matches yours and I get an exception. I've tried two machines, both with the latest JDK, one Windows, one OSX. Same exception.



Then, you can use a 3rd party image library. For example, a quick google gave me https://github.com/imglib/imglib2 . I'm sure there are others, but using a library that has been designed for image manipulation/calculations/etc. instead of displaying may be better. Then display the image in whatever toolkit you want if you still want that.

The same with the HTTP client that people are asking for advice here. Java does come with a decent HTTP/HTTPS library (java.net.URL and friends), that can GET, POST and set headers quite easily. But HttpComponents is quite a bit more powerful than just plain java.net.URL , hence it does get recommended a lot. For simple things, java.net.URL is more than adequate (I know I abused the poo poo out of it 15 years ago, it can do quite a lot ).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply