How to add new view at the top of an existing view in Android?

What is wrong with this Java code [BlueJ] ?

  • I want to make it into a executable file but there is a error coming in the 28th line...) expected...wtf ? import java.io.*; public class STA_Manager { private String name; private int rollno; public void main (String args[]) throws IOException { BufferedReader br=new BufferedReader (new InputStreamReader (System.in)); int choice; System.out.println("\f\n\n\n\t\t\t MAIN MENU "); System.out.println("\n\t\t\t 1. Add new member "); System.out.println("\n\t\t\t 2. View existing members "); System.out.println("\n\t\t\t 3. Exit "); System.out.print("\n\t\t\t Choose [1/2/3] : "); choice=Integer.parseInt(br.readLine()); switch (choice) { case 1 : addmember(); break; case 2 : viewexisting(); break; case 3 : exit(); break; default: main(String args[]); break; } } private void addmember () throws IOException { BufferedReader br=new BufferedReader (new InputStreamReader (System.in)); int choice; System.out.println("\f\n\n\n\t\t\t ADD NEW MEMBER "); System.out.print("\n\t\t\t Name : "); name=br.readLine(); System.out.print("\n\t\t\t Roll No : "); rollno=Integer.parseInt(br.readLine()); System.out.print("\n\t\t\t Please press 1 and then <Enter> to continue : "); choice=Integer.parseInt(br.readLine()); switch (choice) { case 1: main(String args[]); break; default: System.out.print("\n\t\t\t Please press 1 and then <Enter> to continue : "); choice=Integer.parseInt(br.readLine()); } } private void viewexisting () throws IOException { BufferedReader br=new BufferedReader (new InputStreamReader (System.in)); int choice; System.out.println("\f\n\n\n\t\t\t VIEW EXISTING MEMBERS "); System.out.println("\n\t\t\t 1. "+name+":"+rollno); System.out.print("\n\t\t\t Please press 1 and then <Enter> to continue : "); choice=Integer.parseInt(br.readLine()); switch (choice) { case 1: main(String args[]); break; default: System.out.print("\n\t\t\t Please press 1 and then <Enter> to continue : "); choice=Integer.parseInt(br.readLine()); } } private void exit () throws IOException { } }

  • Answer:

    You can not call main() recursively, just one of the rules I don't know why. Maybe try an infinite loop while(1) enclosing your switch case. You do after all have exit() on case 3. Better yet look up events and listeners. I suspect that because main is the entry point into the code there is something happening behind the scene to run a new program. It would be interesting to make a program that only has main(){} and see how big it compiles to wouldn't it?

Sanjeet Suhag at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

You have to call main method like main(args);

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.