David Cone

Ranch Hand
+ Follow
since May 26, 2021
SoCal
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
4
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Cone

I wrote:. . .
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ArrayList cannot be resolved to a type
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (int, int)

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:54)
. . .


Campbell Ritchie wrote:

. . .
when I see "_______ cannot be resolved to a type" and what's in the blank is a Java keyword

No, you will never see a keyword as the type; if you accidentally write a keyword, you will almost certainly get a different error message.

the most likely problem is that I need to import the right API/Class?

No, the most likely explanation is that you have indeed got the imports right and have got a spellling errror sommewhere.



So ArrayList is not a keyword?  If not, what is the proper term?   I'm trying to learn how you came up with your solution of importing java.util.ArrayList.  Could I have gleaned that from the error message when I tried to run it or was that solely from experience?
14 minutes ago

Paul Clapham wrote:You needed a List of DataSet objects, so you spent a dozen lines of code trying to do that. (And failed.) Here's a shorter way of producing the List you need:



That's Java 9; if you're still on Java 8 you'd need one line to create an empty List (like you did) and four lines to add those objects. Your main problem was that you didn't add DataSet objects to your List<DataSet>.



But what if I wanted to do it 30 times?  Or 100?  The point of why I'm trying to change the code from where it last worked to what I'm working on now is that I want to be able to easily add DataSets and run the tests.  That's why I put the data in a simple, easy to read, 2D array.  I want to add new tests simply and easily.  That's the purpose of the "upgrade" I want to do.  I took a Visual Basic course back in 2015, the professor said,. "don't rewrite code."  Typing "new DataSet" for each test seems like rewriting code.  Perhaps I picked too ambitious of an upgrade for my current knowledge level, but I'd still like to find an efficient way to do many tests while adding a minimal amount of code.  Putting a set of braces around a new pair of number and adding a couple of commas seems like the smallest amount of new code per DataSet.

I do plan on taking a Java course this fall (August) but I'm trying to learn as much as I can before then.  BTW, I'm using the current version of Java (16.0.1)  According to my wife (who keeps much better track of time than I do), I've been working on learning Java for two weeks.  I just learned today that you can compile a Java program without running it (from Mr. Campbell)  from his last post where he reiterated "Don't try to run code with compile time errors in [it  ]."  Which baffled me for a while.  I saw a hyperlink was provided and based on what I saw there I searched the internet using DuckDuckGo with "eclipse compile without running" and found this.   So I've already learned something new today.

Anyways, I'm rambling (perhaps to provide pause in deciphering Mr. Campbell's last post.)  

Thank you for taking time to answer my question and I apologize for not being clearer on my intention.

Have a great day,
~d
1 hour ago
Ok, I'm slightly more awake now...  (it's harder, when you don't use caffeine)

Line errors...  Line 29, "local variable baseNum is not used."
                   Line 30, "local variable possibleFactor is not used"

I know they aren't used...... at least not in methods used in this class...  I was intending to use objects of class DataSet to contain the two numbers used in a test, which I want to read from a simple 2D Array.

How can I fix my Constructor so I don't get these errors?  I looked at other examples and stuff, and I just don't know what I'm doing wrong.

(Based on reply from Mr. Campbell") So when I see "_______ cannot be resolved to a type" and what's in the blank is a Java keyword, the most likely problem is that I need to import the right API/Class?  Is there a book that just helps people understand Java compile errors?  Java Compile Errors for Dummies?  I'd buy that book.   I added "import java.util.ArrayList;"

I'll copy the current code again (I think the only change is the extra import but not sure)...

In the code below, if line 58 reads: "listDataSets.add(pair[0], pair[1]);" I get the error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (int, int)

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:58)."

If I change line 58 to: "listDataSets.add(MyIntNum pair[0], pair[1]);" I get the error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
MyIntNum cannot be resolved to a variable
Syntax error on token "pair", delete this token

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:58)"

I'll try putting "MyIntNum" in parentheses to make it a cast?... brb  [back]  That didn't work either.  I got the error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (MyIntNum, int)
Cannot cast from int to MyIntNum

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:58)"

 I'm out of ideas.  What else should I try? (or at this point of frustration, what would work?)
Am I going about this the wrong way in the first place?  The first half of the first line of Dazed and Confused by Led Zepplin floats through my mind in search of something to connect with it.



Thank you for any help you provide,
~d (who's only idea left is: give up for now, because your getting in way over your head.)
5 hours ago

Campbell Ritchie wrote:.

. . .the book . . .

Please always tell us which book, etc. That would let us read it for ourselves.

 My bad... I reference the book title in the comment on line 2 of the code and my 2nd post in the thread is a pic of the code from the page.  Now that I know there's an official way, I'll use it.

Thanks,
~d

(I'll re-read the rest of you post and work on it after I've had my morning yogurt. (Rough night last night))
7 hours ago
OK, I got to thinking about scalability....  What if I wated to do 30 tests?  I'm trying to rewrite the code, but I'm stuck....  I'm not sure how to properly build the DataSet class and I'm getting an error trying to build a list from an array.

new code:


Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ArrayList cannot be resolved to a type
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (int, int)

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:54)



I don't mind hints or articles to read instead of just giving me correct code (though I wouldn't mind correct code either).

Thanks in advance,
~d
21 hours ago
I heard my old visual basic teacher in my head, telling me never repeat code...  Is this over the top or is it OK?

22 hours ago
I heard several of you in my head and made one more change:

23 hours ago
My dad had a saying with enough luck, you don't need many brains....   figured it out....   changed line 24 to :
23 hours ago
OK, I have no idea how to fix this.



Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method setTest(object, int) from the type InstanceMethodDemo refers to the missing type object
The method setTest(object, int) from the type InstanceMethodDemo refers to the missing type object

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:35)
23 hours ago
ok, I got the code working.  So now my main question....  How could we change the code so on lines 31 and 35 we don't have to hardcode the object name...  How could we change that so that I can pass the object name?  I'm going to give it shot.... brb.  ~d
23 hours ago
Here is the code from the book... I typed it in just to ask a question about how to write it better, but I'm getting errors on the program as is.  Note only difference between this and what's in the book is I changed the variable name "ip" in the book to "mip" and I didn't enter the extensive comments. Oh yeah, I used a diffent class name for the main class, and the package name is mine.  I don't know why but I can't get anything in Eclipse IDE to compile using the default package (which is to say not filling in a package name).



returns error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method MyIntNum(int) is undefined for the type InstanceMethodDemo
The method MyIntNum(int) is undefined for the type InstanceMethodDemo

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:28)

My question (had the code worked as I entered it)...  In lines 31 and 35 it hard codes in the object name...  Is there a way to write it where we can pass the object name?  Maybe even pass the Int for the next lines so the code might have something like and later ?


1 day ago
I found an article that explains it more if anyone else is new to the concept.  It's still clear as mud to me, but I'm sure as I'm further along in my java learning,  it will mean more to me.
webpage explaining module-info
1 day ago
When I'm creating a new Java project in Eclipse IDE after I click on "Finish" a new window pops up asking me about creating module-info.java:



What's that about?  DDGing the subject lets me know they started in JDK 9 and let's me somehow limit or include specific code, but what's that mean?  What's an example look like that would make sense to a noob?  I'd guess I won't be needing this for a while, if I select "Don't Create" can I add it later?

Thanks,
~d
2 days ago