Mitul Patell

Greenhorn
+ Follow
since Dec 17, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mitul Patell

Hello all,

I've been tasked with creating a brute force program to solve the 0-1 knapsack problem. I have already set up my program to read data from the input file and to output and store that into variables for the weight, value, knapsack limit, and number of items. I am running into an issue with figuring out how to obtain all subsets of the given set and analyzing it. The following is the input data and my current code:

3

4
5
2 1 3 2
12 10 20 15

5
6
3 2 1 4 5
25 20 15 40 50

6
10
3 2 1 5 5 6
10 10 12 10 12 12




As you can see my solveInstance function is empty. The solveInstance function is meant to discover the amount of feasible subsets, the optimal value and subset, and how many optimal subsets there are.

Any tips to point me in the right direction would be much appreciated.
11 years ago

Darryl Burke wrote:

Mitul Patell wrote:I created the JList before adding it to the panel


Not before the first time you tried to add it to the panel, you didn't.



Oh sorry the code above is not updated. This is the updated code:



And now with this code I'm not getting any errors, but for some reason the JList is not showing up on the Frame at all.
11 years ago

Paul Clapham wrote:It's not that hard. When line 54 is called, the variable jlstColNames is null. You can't add null to a panel, that doesn't make sense. So either remove that line of code or put something before it which assigns a reference to some component to the variable.



I created the JList before adding it to the panel and just setListData in the fetchColumns method. No NullPoint error, but the JList isn't showing up at all. Makes no sense. Any idea why that's happening?
11 years ago
Guess you're out of ideas too.

Well thanks for your time Swastik
11 years ago

Swastik Dey wrote:Which line is throwing npe? Show the exception stack trace.



Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1031)
at java.awt.Container.add(Container.java:352)
at TableViewer2.<init>(TableViewer2.java:54)
at TableViewer2.main(TableViewer2.java:74)
Java Result: 1

Line 54:
Line 74:
11 years ago

Swastik Dey wrote:Try this
...
...



Precisely the same error.
11 years ago

Swastik Dey wrote:Could you please post the updated code?



11 years ago
Just don't understand. It's saying that jlstColNames has a null value?
11 years ago

Swastik Dey wrote:Use the no-arg constructor to create Jlist object, and add it to JPanel in TableViewer2(). In fetch columns method use setListData method to set data to list. As far as the error is concerned, the error is something related to the database.



Yeah I apologize some stupid mistakes by me. I edited that last post for the updated error message right before you posted this. With or without the no-arg constructor and setListData method I am getting the same error.
11 years ago
When I do add the jlstColNames after the for loop, I get a rather long error. I won't post the entire thing here unless someone asks for it, but the main issue seems to be here:

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1031)
at java.awt.Container.add(Container.java:352)
at TableViewer2.<init>(TableViewer2.java:55)
at TableViewer2.main(TableViewer2.java:75)

Is that a normal problem that anyone else has run into?

EDIT:

Line 55:

Line 75:

11 years ago

Darryl Burke wrote:

Mitul Patell wrote:Sorry for the double post. At first it told me it didn't go through. Not sure how to delete my post.



No worries. I've removed it.



Thanks.
11 years ago

Swastik Dey wrote:May be in the fetchColumns method, after the for loop ends.



The problem with that is I can not add that JList to the panel/frame in that case because it is in a separate method. Or maybe there is a way to do that?

EDIT: Nevermind. Mind blanked for a second.
11 years ago

Swastik Dey wrote:The second part of the code can be a method, where you can pass the selected table name, and on combo box change event, you can call that method with the selected table name.





This is precisely what I tried to do a little while ago, however I am unsure of how/where I would then implement the line.
11 years ago
Sorry for the double post. At first it told me it didn't go through. Not sure how to delete my post.
11 years ago
Hello all,

I'm afraid I'm quite the Java beginner so please bear with me.

I've created a database containing eight separate tables with varying amounts of columns. I'm attempting to make a GUI that will let me pick specific columns out of a table and display a JTable of just those columns. So far all I've accomplished is getting the database to connect properly and I've created a JComboBox that holds the names of all of the tables within the database. My next step is getting a JList to fill itself with the columns of the selected Table from the JComboBox. I have absolutely no idea how to go about doing this.

My current code is as follows:



Now I have tried various ways to get the JList to populate itself with the column names but I can't seem to get it. I think I somehow have to use this:



but I'm not really sure.

Any tips would be much appreciated. If I was unclear about anything, please feel free to ask.
11 years ago