Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

groovy example issue

Posted on 2016-10-10
10
103 Views
Last Modified: 2016-10-18
Hi,

I wrote my groovy class as below
class FirstGroovyClass {
String name
String place
def methodOne(){
println "hola"
	}
	static main(args) {
	
	}

}

Open in new window


i wrote my implementation code by creating object as below
import FirstGroovyClass
//class FirstGroovyClassImplementation {

	def object=new FirstGroovyClass()
	object.methodOne()
	
	
	
	def objectTwo=new FirstGroovyClass(name:'FirstGroovyClasse',place:'FirstGroovyClasssss')
	println objecTwo.getName
//}

Open in new window


some how objectTwo is not able to see getName() or getPlace() default methods which groovy should automatically create.

when i ran as groovy script i am getting below error

hola
Caught: groovy.lang.MissingPropertyException: No such property: objecTwo for class: FirstGroovyClassImplementation
groovy.lang.MissingPropertyException: No such property: objecTwo for class: FirstGroovyClassImplementation
      at FirstGroovyClassImplementation.run(FirstGroovyClassImplementation.groovy:10)


please advise
0
Comment
Question by:gudii9
  • 7
  • 2
10 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 41837487
You wrote objecTwo when you probably meant objectTwo.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41837505
even objectTwo same error?
hola
Caught: groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
      at FirstGroovyClassImplementation.run(FirstGroovyClassImplementation.groovy:10)
please advise
0
 
LVL 14

Accepted Solution

by:
CPColin earned 250 total points
ID: 41837508
If Groovy properties act like properties do in other languages, you probably need to type either objectTwo.getName(), with the parentheses, or objectTwo.name, without "get".
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 7

Author Comment

by:gudii9
ID: 41845230
both not working
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 250 total points
ID: 41845910
both not working
Post the new error messages please
0
 
LVL 7

Author Comment

by:gudii9
ID: 41847276
hola
Caught: groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
groovy.lang.MissingPropertyException: No such property: getName for class: FirstGroovyClass
      at FirstGroovyClassImplementation.run(FirstGroovyClassImplementation.groovy:10)
my code is

import FirstGroovyClass
//class FirstGroovyClassImplementation {

      def object=new FirstGroovyClass()
      object.methodOne()
      
      
      
      def objectTwo=new FirstGroovyClass(name:'FirstGroovyClasse',place:'FirstGroovyClasssss')
      println objectTwo.getName
//}


above i am running as Run As---> Groovy script

class FirstGroovyClass {
String name
String place
def methodOne(){
println "hola"
	}
	static main(args) {
	
	}

}

Open in new window


i wonder why EE do not have separate groovy topic? where i can suggest add one?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41847460
any good sample examples around these?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41848736
class FirstGroovyClass {
	String name
	String place
	
	def methodOne(){
		println "hola"
	}
	//static main(args) {
	//}
}

Open in new window


import FirstGroovyClass
//class FirstGroovyClassImplementation {

	def object=new FirstGroovyClass()
	object.methodOne()
	
	
	
	def objectTwo=new FirstGroovyClass(name:'FirstGroovyClasse',place:'FirstGroovyClasssss')
	/*def method1(){
		println objectTwo.name;
	}*/
//}

Open in new window


when i ran FirstGroovyClassImplementation as groovy script i got
hola

i saw examples here which i explore more
https://www.tutorialspoint.com/groovy/groovy_json.htm
0
 
LVL 7

Author Comment

by:gudii9
ID: 41848788
//class GroovyLoop {
	//methodTwenty(){

for(def i=0;i<=10;i++){
	println(i)
}
	//}
	
//}

def j=10;

while(j<20){
	println(j)
	j++
}

Open in new window


above gave

0
1
2
3
4
5
6
7
8
9
10
10
11
12
13
14
15
16
17
18
19
0
 
LVL 7

Author Comment

by:gudii9
ID: 41848813
//class GroovyLoop {
	//methodTwenty(){

for(def i=0;i<=10;i++){
	println(i)
}
	//}
	
//}

def j=10;

while(j<20){
	println(j)
	j++
}

def list1=[1,4,6]
for(def z:list1)
println(z)


1.upto(5){
	println("EE")
}


1.step(6,3){
	println"$it"
}

3.times{
	println"EEE"
}


def arr=new String[3]
arr[0]="one"
arr[1]="two"
arr[2]="three"
println arr

println arr.length
println arr.size()
def arrInt=[1,2,5] as Integer[]
println arrInt.min()

def list=[]
println list.size


def lists=new ArrayList<String>()

def listss=[9,8,0]

lists.add("ep");
println lists

lists << "eh"
println lists

lists.push("ss")
println lists

lists.putAt(1,"zz")
println lists

println lists[1]

println lists.get(2)
println lists.getAt(0)
println lists[-1]

println lists.remove("zz")
println lists
lists.add("ep1");
lists.add("ep2");
lists.add("ep3");
 lists.remove(2)
 println lists
 
 lists=lists - "ep2"
 println lists
 
 
 def listNum=[1,6,4,7,9,0,2,9]
 println listNum.count(9)
 
 println listNum.sort()
 
 def liste=[4,7,[9,0],2,4,8]
 println liste
 println liste.flatten()
 
 
 def mapEx=[:]
 mapEx.put('color','blue')
 println mapEx.size()
 
 mapEx['size']='low'
 println mapEx.size()
 
 mapEx.length='22'
 println mapEx.size()
 
 mapEx << ['height':"39"]
 println mapEx.size()
 
 println mapEx['height']
 println mapEx.height
 
 def file=new File('TestFile.txt')
 println file.text
 
 
 def files=new File('TestFile.txt')
 println files.readLines()[3]
 
 println files.readLines().each {
	 line ->println line
 }
 
 
 
 files.readLines().each {
	 line ->line.tokenize().each{
		 word ->if(word=='e'){
			 println word
		 }
	 }
 }
 
 
 files.readLines().each {
	 line ->line.tokenize().each{
		 word ->
		 println word
	 }
 }
 
 
 def fileee=new File('TestFile.txt')
 //println fileee.absolutePath
 
 println file.size()
 
 println "File ? ${fileee.isFile()}"
 println  "Director ? ${fileee.isDirectory()}"
 
 //println file.renameTo('TestFile3.txt')
 
 def fils=new File('writeHere.txt')
 fils.write("blah")
 fils << "next blah"
 
 
 
 
 
 

Open in new window


0
1
2
3
4
5
6
7
8
9
10
10
11
12
13
14
15
16
17
18
19
1
4
6
EE
EE
EE
EE
EE
1
4
EEE
EEE
EEE
[one, two, three]
3
3
1
0
[ep]
[ep, eh]
[ep, eh, ss]
[ep, zz, ss]
zz
ss
ep
ss
true
[ep, ss]
[ep, ss, ep2, ep3]
[ep, ss, ep3]
2
[0, 1, 2, 4, 6, 7, 9, 9]
[4, 7, [9, 0], 2, 4, 8]
[4, 7, 9, 0, 2, 4, 8]
1
2
3
4
39
39
qqqq xxggg
sss
zz
e
tttttttttt
aaanext blah
e
qqqq xxggg
sss
zz
e
tttttttttt
aaanext blah
[qqqq xxggg, sss, zz, e, tttttttttt, aaanext blah]
e
qqqq
xxggg
sss
zz
e
tttttttttt
aaanext
blah
48
File ? true
Director ? false
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question