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;
}
}
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
If BPMClass
is declared as public, then code is fine.
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;
}
}
精彩评论