M.A.Murali
M.A.Murali

Reputation: 10148

How to call a Java class from a Android Activity

I have an Android activity called main.java and BPMClass.java class. I need to call the BPMClass.java within the main.java class. I wrote the code in the following way (does not show function name):

import com.app.BPMClass;
... 
public class main extends Activity {
BPMClass bpmclass;
@Override
public void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    bpmclass = new BPMClass("filename");
    bpmclass.    // does not show the function name of BPMClass.
  }
}

....
BPMClass{
   String fname;
   public BPMClass(String filename){
    fname=filename
   }
  public int fun1(fname){
   int val=0;
    .......
  return val; 
 }
}

Upvotes: 2

Views: 15214

Answers (3)

PedroAGSantos
PedroAGSantos

Reputation: 2346

problem is simple if he try to place class after name of the class

   class BPMClass{
   String fname;
   public BPMClass(String filename){
    fname=filename
   }
  public int fun1(fname){
   int val=0;
    .......
  return val; 
 }
}

Upvotes: 0

Zoombie
Zoombie

Reputation: 3610

Declared access modifier of class as according to your need, if class needed to access from its package level, then this should work fine.. else declare it as public

Upvotes: 6

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43088

If BPMClass is declared as public, then code is fine.

Upvotes: 2

Related Questions