java - confusing Android SDK error: static reference to non-static method -
can explain why in line 6 of following code (contained in .java file i'm working on in adt eclipse ide) i'm getting error marker:
"cannot make static reference non-static method getremotedevice(string) type bluetoothadapter"
import android.bluetooth.*; public final class bluetooth{ void initconnection(string address){ bluetoothsocket sock = bluetoothadapter.getremotedevice(address).createinsecurerfcommsockettoservicerecord(00001101-0000-1000-8000-00805f9b34fb); } }
what in above code makes static? , why not handed same error use of createinsecurerfcommsockettoservicerecord
method of bluetoothdevice?
you can't can't call getremotedevice() on bluetoothadapter class, it's not static method. need instance, this:
bluetoothadapter adapter = bluetoothadapter.getdefaultadapter(); bluetoothsocket sock = adapter.getremotedevice(address) .createinsecurerfcommsockettoservicerecord(00001101-0000-1000-8000-00805f9b34fb);
Comments
Post a Comment