Can someone please help me find out wtf am I doing wrong trying to populate a jList?

|
Dieggo 2022-09-19 20:56:23
Thanks @JFCostta that website you sent helped me in some points it is very nice.
martin_angelo 2022-09-19 21:13:00
in your defense: He said he would be using Streams and the Stream-API. So totally understandable. Though it reminds me of requirement engineering to always make sure to understand what the customer really means 😅
martin_angelo 2022-09-19 21:15:19
Dieggo 2022-09-19 20:56:23
Thanks @JFCostta that website you sent helped me in some points it is very nice.

+1
mkyong is always a good source for java questions

JFCostta 2022-09-19 21:17:34
martin_angelo 2022-09-19 21:13:00
in your defense: He said he would be using Streams and the Stream-API. So totally understandable. Though it reminds me of requirement engineering to always make sure to understand what the customer really means 😅

Thanks, you’re a very kind man 😁.

Eng_Rastin 2022-09-22 17:58:50
hi
every one who wants to learn java for free from A to Z
tell me or comes pv.
im full stack developer
i wana help you to learn more
100 % off
marianepepe 2022-09-22 23:32:32
Hi guys, what’s up?

Anyone *Dev Java or Dev .net with at least 5 years of experience and a good level of English OR French* who is interested in living and working in Montreal?

Call me on LinkedIn

Https://www.linkedin.com/in/mariane-pepe

Merci 🇨🇦🇧🇷

R_r_F_BR 2022-09-23 05:25:02
Finally it’s here Jakarta EE 10.

The Eclipse Foundation’s Jakarta EE Working Group Releases Jakarta EE … | The Eclipse FoundationJakarta® EE: The New Home of Cloud Native Java
Jakarta EE 10 provides new functionality in over 20 component specifications through version updates reflected in the specified APIs.
IsTechAdmin 2022-09-23 17:32:28
hi guys
everybody who wants to read java from A to Z complete and simply for free text me
or replay the sms
IsTechAdmin 2022-09-24 19:32:15
hi guys
Im full stack developer
I create a channel for helping new people in this term
So
everybody who wants to read java from A to Z complete and simply for free text me
or replay the sms
Victor_VBA 2022-09-25 21:04:49
Hi.
Can someone please help me find out wtf am I doing wrong trying to populate a jList? Here’s the code:

DefaultListModel<String> lista = new DefaultListModel<>();
for(String item : i.ItensEmVetor()) {
lista.addElement(item);
}
System.out.println(lista);

The println prints correctly. But when I try to populate my jList with its method .setModel(lista); it returns this error:

Uncompilable code – non-static variable jList_Inventario cannot be referenced from a static context

I can’t seem to find any explanation whatsoever and I’d be glad to hear any suggestion.

martin_angelo 2022-09-25 22:30:56
Hi Victor,
can you please provide more code? Specifically the part, that includes the use of jList_Inventario. If it is a lot of code, you can use code-sharing websites like https://codefile.io/
Also provide more lines of the error message.

Codefile — Share code in real time⚡️Codefile.io
Create collaborative code files online for your technical interviews, pair programming, teaching, etc.
Jaschar 2022-09-26 09:32:35
Victor_VBA 2022-09-25 21:04:49
Hi.
Can someone please help me find out wtf am I doing wrong trying to populate a jList? Here’s the code:

DefaultListModel<String> lista = new DefaultListModel<>();
for(String item : i.ItensEmVetor()) {
lista.addElement(item);
}
System.out.println(lista);

The println prints correctly. But when I try to populate my jList with its method .setModel(lista); it returns this error:

Uncompilable code – non-static variable jList_Inventario cannot be referenced from a static context

I can’t seem to find any explanation whatsoever and I’d be glad to hear any suggestion.

Hi Victor,

First of all, we are not psychics. How are we supposed to help you if we don’t know your custom code?

So we can’t even meaningfully guess what is causing this error.

If you can’t share your full project, I see little chance that we can help you.

If you can, I would like to ask you to share the project (or at least the relevant code) with JDoodle in Advance Mode:

https://www.jdoodle.com/online-java-compiler-ide/

Furthermore, I would like to ask you to provide
a short but complete example which demonstrates the problem to the best of your ability.

Victor_VBA 2022-09-26 15:35:51
martin_angelo 2022-09-25 22:30:56
Hi Victor,
can you please provide more code? Specifically the part, that includes the use of jList_Inventario. If it is a lot of code, you can use code-sharing websites like https://codefile.io/
Also provide more lines of the error message.

Thanks for your message, Martin. Sorry for not getting back here in time.
A good samaritan from this group happened to have identified the mistake I was making and showed me in private message. I’ll leave the solution here for the sake of anyone who’d eventually stumble upon it.

public class jFrame extends javax.swing.JFrame {

public jFrame() {
initComponents();
populate_jList(); // call the void

public void populate_jList() {

ArrayList inv = new ArrayList();
inv.LoadItems(); // method to load items into inv
DefaultListModel inventory = new DefaultListModel();

// the ItemToString method returns a String
inv.ItemToString().forEach(x-> {
inventory.addElement(x);
});
jList.setModel(inventory);
}

Victor_VBA 2022-09-26 15:37:11
Jaschar 2022-09-26 09:32:35

Hi Victor,

First of all, we are not psychics. How are we supposed to help you if we don’t know your custom code?

So we can’t even meaningfully guess what is causing this error.

If you can’t share your full project, I see little chance that we can help you.

If you can, I would like to ask you to share the project (or at least the relevant code) with JDoodle in Advance Mode:

https://www.jdoodle.com/online-java-compiler-ide/

Furthermore, I would like to ask you to provide
a short but complete example which demonstrates the problem to the best of your ability.

Hi, Jaschar,

Sorry for not sharing the same view that making fun of someone by suggesting he’d be expecting others to be psychic would somehow contribute to the solve of a problem.

Like I said in the previous message, a good samaritan from here was sufficiently able to identify the problem with the information I provided.

Jaschar 2022-09-26 16:08:34
Victor_VBA 2022-09-26 15:37:11
Hi, Jaschar,

Sorry for not sharing the same view that making fun of someone by suggesting he’d be expecting others to be psychic would somehow contribute to the solve of a problem.

Like I said in the previous message, a good samaritan from here was sufficiently able to identify the problem with the information I provided.

Hi Viktor,

Sorry, that you got the impression that I was making fun of someone.

This is just a common expression in German (specifically in Berlin) when someone provides too little information on a topic.

to be honest, i was also a bit annoyed by the lack of information. As Admin I saw this too many times in the past. So this annoyance was not just directed at you, but at all the requests with insufficient information.

Jaschar 2022-09-26 16:10:39
I am glad someone could help you.
Victor_VBA 2022-09-26 16:11:30
Jaschar 2022-09-26 16:08:34
Hi Viktor,

Sorry, that you got the impression that I was making fun of someone.

This is just a common expression in German (specifically in Berlin) when someone provides too little information on a topic.

to be honest, i was also a bit annoyed by the lack of information. As Admin I saw this too many times in the past. So this annoyance was not just directed at you, but at all the requests with insufficient information.

Oh, I got it 😅

Victor_VBA 2022-09-26 16:13:13
Jaschar 2022-09-26 16:10:39
I am glad someone could help you.

Yes, the person asked for discretion, though, so I gladly provided the solution in case someone else needs it.

Victor_VBA 2022-09-27 05:26:33
Hi. I was wondering if there is a way for me to populate jComboBox with class instances rather than only Strings. I’ve been searching for it for quite some time, but no luck so far… If anyone has any idea as how to do that, i’m all ears (eyes) 😁
Eng_Rastin 2022-09-27 08:50:19
hi
every one
i am full stack developer and i wana help people
who wants to learn java for free from A to Z
tell me or comes pv.
im full stack developer
i wana help you to learn more
100 % off
|