java - Android. How to access a class from another file to MainActivity -


i created separate java class called setip.java simple print:

package com.myname.appname;  import android.util.log;  public class setip {      public void hello(){         log.d("system", "hello world!");     } } 

in mainactivity try call by:

public class mainactivity extends appcompatactivity {      setip setip = new setip();     setip.hello();    // oncreate , stuff } 

but error said cannot resolve symbol 'hello'. please help. thanks

you shouldn't call method of object of of classes on fly calling now, told // oncreate , stuff below object's method call.

it has inside constructor or methods, here

setip setip = new setip(); @override    public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setip.hello();    } 

or

@override    public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setip setip = new setip();       setip.hello();    } 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -