Can someone please help me find out wtf am I doing wrong trying to populate a jList?
can you please provide more code?
+1
mkyong is always a good source for java questions
Thanks, you’re a very kind man 😁.
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
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 🇨🇦🇧🇷
Jakarta EE 10 provides new functionality in over 20 component specifications through version updates reflected in the specified APIs.
everybody who wants to read java from A to Z complete and simply for free text me
or replay the sms
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
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.
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.
Create collaborative code files online for your technical interviews, pair programming, teaching, etc.
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.
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);
}
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.
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.
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 😅
Yes, the person asked for discretion, though, so I gladly provided the solution in case someone else needs it.
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