Hi,
In the box below is what I have to do. I'm having errors in my code and can't figure out what is wrong. If anyone can help that'd be great.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi,
In the box below is what I have to do. I'm having errors in my code and can't figure out what is wrong. If anyone can help that'd be great.
Last edited by Rkelly155; April 10th, 2012 at 09:05 PM.
Please explain. If you are getting error messages, please copy the full text and paste here.I'm having errors in my code and can't figure out what is wrong.
If you don't understand my answer, don't ignore it, ask a question.
4 errors found:
[line: 57]
Error: char cannot be dereferenced
File: [line: 71]
Error: char cannot be dereferenced
File: [line: 84]
Error: char cannot be dereferenced
[line: 98]
Error: MyString.java:98: incompatible types
found : java.lang.String
required: MyString
Last edited by Rkelly155; April 10th, 2012 at 09:06 PM.
Can you copy the full text of the compiler's error messages? I would expect them to look like this:
Notice that the error message includes the source line and a ^ beneath where the error is.TestSorts.java:138: cannot find symbol symbol : variable var location: class TestSorts var = 2; ^
For this error:
You can't call a method using a char variable. For example: 'a'.aMethod() is not validchar cannot be dereferenced
"a".length() is valid because "a" is a String object
What statement is line 98?
If you don't understand my answer, don't ignore it, ask a question.
I still don't understand. I need to call string[i] because it's the array that I need to use.
and line 98 is
Last edited by Rkelly155; April 10th, 2012 at 09:05 PM.
You posted 8 lines. Which one is line 98?
The method is defined to return a MyString object. Is that what you want it to do?
Where is there a MyString object that can be returned?
If you don't understand my answer, don't ignore it, ask a question.
The MyString object that gets returned is what I have to create in the tester class I think. I have to create a class with these methods than make a tester class that will use these methods on a string that I will give in a constructor. Hopefully that made sense.
To create a MyString object you need to use the new statement:
MyString myStr = new MyString(<SOME ARGS HERE?>);
then at the end of the method:
return myStr;
If you don't understand my answer, don't ignore it, ask a question.
I'm just struggling with the methods that need to be created. Is there anyway, based off of my code, that you can see I did something wrong? Or how would you code the methods?
Please define what the method is supposed to do. What arguments does it receive, what processing does it do and what does it return?
If there is more than one method, do the above steps for each method.
If you don't understand my answer, don't ignore it, ask a question.
I have included the methods i need to create in the class all the way above in the box above my code that I have so far.
If you have definitions of what the methods should do, then you need to design the code for each one before you code it.
Pick one, design it, code it, compile it test it. When it works, move on to the next one.
Last edited by Norm; April 10th, 2012 at 08:50 PM.
If you don't understand my answer, don't ignore it, ask a question.
Cross posted at: MyString Help
If you don't understand my answer, don't ignore it, ask a question.
rewrite your code then write your error...