有谁知道为什么我总是在“myService.getMountPoint();”中得到空指针?
我想我做的几乎和网上的例子一样。
public class mainActivity extends Activity {
/** Called when the activity is first created. */
private IMountService myService = null;
private ServiceConnection conn = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
myService = IMountService.Stub.asInterface(service);
}
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bindService(new Intent(mainActivity.this, DeviceStatusService.class), conn,
Context.BIND_AUTO_CREATE);
startService(new Intent(mainActivity.this, DeviceStatusService.class));
try {
myService.getMountPoint();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}