?
Solved

groovy example issue

Posted on 2016-10-10
10
Medium Priority
?
130 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
[X]
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
  • 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 1000 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
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
LVL 7

Author Comment

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

Assisted Solution

by:mccarl
mccarl earned 1000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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…
Suggested Courses

770 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