Solved

groovy example issue

Posted on 2016-10-10
10
70 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now