Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Walter confetti

Help with android programming

Recommended Posts

Hello guys!

In these months i'm trying to learn how to program on Android engines for making an APP for the said OS using Eclipse, Android Studio and learning some Java programming, i'm just at the bare bones of the full thing, and Java is a little difficult to understand for me, like this thing for example:

why this is ok for eclipse

Spoiler

package it.devapp.corsojava.poliformismo;

import java.awt.Color;
import java.awt.Point;

public class PoliformismoDemo {
	
	public interface Moveable {
		void move(double x, double y);
	}
	
public abstract class GraphicObject {
		protected Color color;
		protected Color borderColor;
		protected int border;
		
		public Color getColor() {
			return color;
		}
		
		public void setColor(Color color) {
			this.color = color;
		}
		
		public Color getBorderColor() {
			return borderColor;
		}
		
		public void setBorderColor(Color borderColor) {
			this.borderColor = borderColor;
		}
		
		public int getBorder() {
			return border;
		}
		
		public void setBorder(int border) {
			this.border = border;
		}
		
		public abstract void draw();
		
public class Circle extends GraphicObject implements Moveable{
	private Point center;
	private double radius;
	
	public Point getCenter() {
		return center;
	}
	
	public void setCenter(Point center) {
		this.center = center;
	}
	
	public double getRadius() {
		return radius;
	}
	
	public void setRadius(double radius) {
		this.radius = radius;
	}
	
	@Override
	public void draw () {
			System.out.println("Disegno un cerchio");
	}
	
	@Override
	public void move(double x, double y) {
		this.center.x += x;
		this.center.y += y;
	}
}

public class Rectangle extends GraphicObject {
	private Point topLeft;
	private Point bottomRight;
	
	public Point getTopleft() {
		return topLeft;
	}
	
	public void setTopLeft(Point topLeft) {
		this.topLeft = topLeft;
	}
	
	public Point getBottomRight() {
		return bottomRight;
	}
	
	public void setBottomRight(Point bottomRight) {
		this.bottomRight = bottomRight;
	}
	
	@Override
	public void draw() {
		System.out.println("Disegno un rettangolo");
	}
	
}


public class GraphicObjectTest {
	public void main(String[] args) {
		GraphicObject cerchio= new Circle ();
		GraphicObject rettangolo = new Rectangle();
		
		cerchio.draw();
		rettangolo.draw();

	}

}
}
}

but when it came to testing it, this doesn't work for the emulated engine,saying that this doesn't work if i can't put a static camp in the final script, but when i put the said camp in the script, it says: "The method main cannot be declared static; static methods can only be declared in a static or top level type"?

Can you guys help me? Did another one here knows how to program in Android?

Thanks for the attention you gave me and if this post isn't good for DW hell it.

Share this post


Link to post

I think it's the fact that everything seems to be nested inside GraphicsObject, try splitting the file up into different class files and importing them, rather than this super-object. I'm having a slight bit of trouble following the brackets but it looks like the hierarchy is this:

PoliformismoDemo
   > Moveable
   > GraphicObject
      > Circle
      > Rectangle
      > GraphicObjectTest
          > main()
You want the above to be more flat, with main() only being one layer down.

I can't say for sure because I'm about to leave for work, and I don't have time to set up a project to see for myself.

Share this post


Link to post

On the top of my head, in Android as well as in Java Applet programming you're not even supposed to define a main() method anywhere in your class: the way your program starts/stops and generally interacts with the OS is totally different.

If you want me to be brutally honest though, I don't that asking questions at this point will benefit you. After you've mastered the basics of the language itself and those of Android programming, then we're talking.

FWIW, a colleague of mine once organized a kind of "Hell's Week" course in Android programming, aimed at people who weren't familiar with either Java or Android. It worked well enough to get them to create a simple app with basic GUI interaction within a week, but it was an intensive, 6-hour a day course full of determined people (willing to give up part of their summer vacations).

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×