Solved

groovy example issue

Posted on 2016-10-10
10
119 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 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 7

Author Comment

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

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 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