tony baloni

Greenhorn
+ Follow
since Oct 19, 2018
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 tony baloni

Randy Tong wrote:These two lines should follow the targetSdkVersion.
For me, I set targetSdkVersion as 27, so this line should be



Thank you for the reply.
The thing is implementation 'com.android.support:appcompat-v7:28.0.0' is automatically gernerated when I started a new project. So I assume it is the right version. I use lollipop 5.1 on my Android Studio. The implementation 'com.android.support:support-v4:23.4.0' is I copied from a sample frome a tutorial code which is a few years old. So I assume it is out of date. How do I know which verson goes with 'com.android.support:appcompat-v7:28.0.0'? My SDK Manager looks like this, don't know if it matters.
5 years ago
Hello, I am using Andriod Studio 3.2.1. In the build. gradle (app), I have:
dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   testImplementation 'junit:junit:4.12'
   implementation 'com.android.support:appcompat-v7:28.0.0'
   implementation 'com.github.bumptech.glide:glide:3.7.0'
   implementation 'com.android.support:support-v4:23.4.0'
   implementation 'com.mcxiaoke.volley:library:1.0.19'
   implementation 'com.google.code.gson:gson:2.6.1'
   implementation 'com.github.pavlospt:circleview:1.2'
}

Now implementation 'com.android.support:appcompat-v7:28.0.0' and implementation 'com.android.support:support-v4:23.4.0' both has a red under curly score, why is that?
5 years ago

Carey Brown wrote:Looks like your ClassA is trying to use print() from your previous version of ClassB. Can you do a clean rebuild of all the java files? If not, can you find where the .class files are being kept and delete them all?



It was odd, shortly after I posted, it worked as expected.

5 years ago
I have two classes, ClassA and ClassB. I tried to pass a char '1' to ClassA to ClassB, I got an error "reason: actual and formal argument lists differ in length". How could it be different length?

5 years ago

Carey Brown wrote:
True. Comment out line 3.



I am glad you point that out. In fact the entire method

is not needed, I wasn't sure if I was correct.
5 years ago

Carey Brown wrote:

tony baloni wrote:I followed Carey Brown' instruction I created two files HelloWorld.java and GoodbyWorld.java I put them in a folder called java_exercises than I cd to this directory,  javac them. When I did javac HelloWorld.java it generate a HelloWorld.class as well as a GoodbyeWorld.class, But when I try to run it. java HelloWorld, the terminal give this error:
Error: Could not find or load main class .Users.tony.Desktop.java_exercises.HelloWorld
What have I done wrong?


Did you cd into the same directory to run the program?

You aren't declaring any 'package's in the .java files?

You could try adding in class path:





After some trial and error, I solved the problem. Yes I did cd into the correct directory and I didn't have to use any packages at all. However, I use the same approach on this :




I get the folowing errors
javac HelloWorld.java
./GoodbyeWorld.java:3: error: non-static method print() cannot be referenced from a static context
       print();
       ^
javac GoodbyeWorld.java
GoodbyeWorld.java:3: error: non-static method print() cannot be referenced from a static context
       print();
       ^

5 years ago

Carey Brown wrote:This would be a better approach; creating static print() methods to do the work.



I followed Carey Brown' instruction I created two files HelloWorld.java and GoodbyWorld.java I put them in a folder called java_exercises than I cd to this directory,  javac them. When I did javac HelloWorld.java it generate a HelloWorld.class as well as a GoodbyeWorld.class, But when I try to run it. java HelloWorld, the terminal give this error:
Error: Could not find or load main class .Users.tony.Desktop.java_exercises.HelloWorld
What have I done wrong?


5 years ago

Harry Kar wrote:

tony baloni wrote:Hello, I am a total newbie to start to learn Java,. So many tutorials start with IDE. In order to get a clear understanding of how java work, I don't want  any distractions from  IDEs, I just want to do it in a plain text editor.



Your point  about starters and heavy IDE's is absolutely right i can say i hear it only rarely trough starters.But you have to know other than heavy/professional IDE's(e.g. NetBeans, Eclipse, IntelliJ)  out there exist also very simple "IDE's" specifically thought and implemented for students/starters(for teaching/learning) e.g. BlueJ and  DrJava . They are written in java and offer only a bit more than a plain text editor so no distraction

Apart  your specific question here are few pointers to help you go further:
1. It's recommended when one start to learn OO Programming other than start learn the language itself he/she choose,  start learn also about OO Design. Really the later in my humble opinion is more important and applicable to any language.  

2. take a look in that thread OOP, what is an Object? i guess you will find it useful

3. Take a look (often) in our small(in expansion) library of good open texts ; start look at the section Beginners books  subsections OO related and Java; Everything you choose there it's good  
If you have no idea where to start get a try  for example at
  • Think Java How to Think Like a Computer Scientist 2002 by Allen B. Downey
  • Introduction to Programming Using Java, Version 7.0, August 2014 by David J. Eck
  • Object-Oriented Programming used Java 2006 by David J. Eck, et al
  • Object-oriented Programming in JavaTM Textbook by Richard L. Halterman 2008(use DrJava)
  • OOP - Learn Object Oriented Thinking & Programming 2013 by Rudolf Pecinovsky (use BlueJ)


  • Downey's small textbook is almost ideal for starters(is small and uses the necessary Java's subset for start and avoid student's overwhelming) i guess  
    The last (Pecinovsky) is made  in a particular way (respectively of other traditional textbooks) trough dialogs between an hypothetical student/learner and his teacher

    And ... Welcome to Ranch!  



    Thanks for your input. I remember in the old days when I started programming in then Obj-C for iOS. I started with XCode. It was quite a struggle joggling between XCode and Obj-C . Later on I realized that there were a lot of basics I don't understand., such the compile and linking process and program structure because XCode did all that for me. I am going to learn the "hard" way-with just a simple good old text editor and the Terminal, so that I have better understanding
    As for as OOP concern, I think I have a pretty good grab on it, but I will read some of the books recommended.
    Now as for the usage of javac -d, I still need some time to search for the answer.
    5 years ago
    Thanks. On my Mac in Terminal I use javac to compile my two classes. but in the non-static method. I need to compile the two files (both files are in the same directory) together so I use javac -d GoodbyeWorld.java HelloWorld.java
    The Terminal gave
    javac: not a directory: GoodbyeWorld.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    What is the correct syntax for javac -d?
    5 years ago
    Thank you again for all you guys helps. Now it start to make sense to my little brain So what are the pros and cons in using static and non-static? In what situation would I use one or the other? Does it have to do with code security?
    5 years ago

    Carey Brown wrote:This would be a better approach; creating static print() methods to do the work.



    Thank you for your reply. More question, sorry. Howcome in the second method, I don't need something like xyz = new GoodbyeWorld to create an object before I use its method?
    5 years ago
    Hello, I am a total newbie to start to learn Java,. So many tutorials start with IDE. In order to get a clear understanding of how java work, I don't want  any distractions from  IDEs, I just want to do it in a plain text editor.
    Now I create two files in BBedit, one is HelloWord.java

    The other one is GoodbyeWorld.java


    I compiled them individually, then run them, they both work fine.

    Now I need to learn how to link the two files, so that when I run HelloWorld. It will output Goodbye, World instead. How do I use the method from the other class? What is the syntax?Thanks

    5 years ago

    Adrian Grabowski wrote:Something like this should work I think



    Thanks for the reply. That's something I don't understand. This code block


    is already created in the class Test.java, do I have to write it again in TestUI.java? If I make a.serialWrite('x') into a function in Test.java, can't the TestUI jbutton addActionListener just call that function from Test.java? I am not sure how the Test.java class can link to TestUI.java.
    5 years ago

    Adrian Grabowski wrote:You really want to start with learning some basics of Java before jumping into more complicated things but if you just want to add some code to your button you just call addActionListener on it.



    Can you give me a simple code example? Please.
    5 years ago