タブホストアクティビティ内でサービスをバインドする方法に取り組んでいます
私は Remoteserviceconnection という名前の依存関係プロジェクトを持っています。タブホストの子アクティビティ内で inokeservice() を呼び出しています。
私が言ったように、3 つの子アクティビティを持つタブホスト アクティビティがあり、子アクティビティ内でサービスをバインドしたいのですが、ヌル ポインター例外が発生しています。
私はこれらの2つのリンクをたどりましたが、まだアイデアが得られません
基本クラスのアクティビティを使用して複数のアクティビティ (タブ) をサービスにバインドする
http://code.google.com/p/android/issues/detail?id=2483
私のプロジェクトには4つのアクティビティがあります
1) TabBarExample.java 2) FirstTab.java 3) SecondTab.java 4) ThirdTab.java
私は正確に何を間違っていますか?
どんな助けでも大歓迎です、ありがとう
これが私のコードで、このJavaファイルでエラーが発生しています。
FirstTab.java
 public class FirstTab extends Activity {
protected static final String TAG = "HvacActivity";
/** Called when the activity is first created. */
private IMyRemoteService remoteService;
private boolean started = false;
private RemoteServiceConnection conn = null;
private Handler serviceHandler;
private static int speed;
private static int hvactemp;
private static int hvacTemppass;
private Task myTask = new Task();
private ImageView fanimgview;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.hvac);
    if(started == false )
    startService();
    bindService();
    System.gc();
    serviceHandler = new Handler();
    serviceHandler.postDelayed(myTask, 1000L);
}
class RemoteServiceConnection implements ServiceConnection {
    // static final int hvactemp = 0;
    public void onServiceConnected(ComponentName className,
            IBinder boundService) {
        remoteService = IMyRemoteService.Stub
                .asInterface((IBinder) boundService);
        Log.d(getClass().getSimpleName(), "onServiceConnected()");
    }
    public void onServiceDisconnected(ComponentName className) {
        remoteService = null;
        // updateServiceStatus();
        Log.d(getClass().getSimpleName(), "onServiceDisconnected");
    }
};
private void startService() {
    if (started) {
        // Toast.makeText(CarHome.this, "Service already started",
        // Toast.LENGTH_SHORT).show();
    } else {
        Intent i = new Intent();
        i.setClassName("com.msat.home.clusterservices",
                "com.msat.home.clusterservices.RemoteService");
        startService(i);
        started = true;
        updateServiceStatus();
        Log.d(getClass().getSimpleName(), "startService()");
    }
}
private void stopService() {
    if (!started) {
        // drivertmpcount.setText(Integer.toString(hvactemp)); //
        // Toast.makeText(CarHome.this, "Service not yet started",
        // Toast.LENGTH_SHORT).show();
    } else {
        Intent i = new Intent();
        i.setClassName("com.msat.home.clusterservices",
                "com.msat.home.clusterservices.RemoteService");
        stopService(i);
        started = false;
        updateServiceStatus();
        Log.d(getClass().getSimpleName(), "stopService()");
    }
}
private void bindService() {
    if (conn == null) {
        conn = new RemoteServiceConnection();
        Intent i = new Intent();
        i.setClassName("com.msat.home.clusterservices",
                "com.msat.home.clusterservices.RemoteService");
        bindService(i, conn, Context.BIND_AUTO_CREATE);
        updateServiceStatus();
        Log.d(getClass().getSimpleName(), "bindService()");
    } else {
        // Toast.makeText(CarHome.this,
        // "Cannot bind - service already bound",
        // Toast.LENGTH_SHORT).show();
    }
}
private void releaseService() {
    if (conn != null) {
        unbindService(conn);
        conn = null;
        updateServiceStatus();
        Log.d(getClass().getSimpleName(), "releaseService()");
    } else {
        // Toast.makeText(CarHome.this, "Cannot unbind - service not bound",
        // Toast.LENGTH_SHORT).show();
    }
}
private void invokeService() { // getting ERROR here
    if (conn == null) {
        // Toast.makeText(CarHome.this, "Cannot invoke - service not bound",
        // Toast.LENGTH_SHORT).show();
    } else {
        try {
            System.out.println(remoteService);
            final TextView drivertmpcount = (TextView) findViewById(R.id.curtempcount);
            // final TextView tempcountpass = (TextView)
            // findViewById(R.id.tempcountpass);
            hvactemp = remoteService.getHvacTemp();  // getting ERROR here
            hvacTemppass = remoteService.getHvacTemppass();
            System.out.println("Raghav hvac" + hvactemp);
            System.out.println("jaydeep speed" + speed);
            // rpm_text.setText(rpm);
            drivertmpcount.setText(Integer.toString(hvactemp));
            // tempcountpass.setText(Integer.toString(hvacTemppass));
            Log.d(getClass().getSimpleName(), "invokeService()");
        } catch (RemoteException re) {
            Log.e(getClass().getSimpleName(), "RemoteException");
        }
    }
}
private void updateServiceStatus() {
    String bindStatus = conn == null ? "unbound" : "bound";
    String startStatus = started ? "started" : "not started";
    String statusText = "Service status: " + bindStatus + "," + startStatus;
    // TextView t = (TextView)findViewById( R.id.serviceStatus);
    // t.setText( statusText );
    System.out.println("Jaydeep : " + statusText);
}
protected void onDestroy() {
    super.onDestroy();
    releaseService();
    Log.d(getClass().getSimpleName(), "onDestroy()");
}
class Task implements Runnable {
    public void run() {
        invokeService();  // getting ERROR here
        // serviceHandler.postDelayed(this, 1000L);
        //Log.i(getClass().getSimpleName(),
        //      "Incrementing engineRPM in the run method");
    }
}
}
ログキャットメッセージ
   09-06 19:12:36.550: E/AndroidRuntime(14116): FATAL EXCEPTION: main
   09-06 19:12:36.550: E/AndroidRuntime(14116): java.lang.NullPointerException
   09-06 19:12:36.550: E/AndroidRuntime(14116):     at com.hvaccontroller.msat.FirstTab.invokeService(FirstTab.java:145)
   09-06 19:12:36.550: E/AndroidRuntime(14116):     at com.hvaccontroller.msat.FirstTab.access$1(FirstTab.java:132)
   09-06 19:12:36.550: E/AndroidRuntime(14116):     at com.hvaccontroller.msat.FirstTab$Task.run(FirstTab.java:180)
  09-06 19:12:36.550: E/AndroidRuntime(14116):  at android.os.Handler.handleCallback(Handler.java:587)
  09-06 19:12:36.550: E/AndroidRuntime(14116):  at android.os.Handler.dispatchMessage(Handler.java:92)
  09-06 19:12:36.550: E/AndroidRuntime(14116):  at android.os.Looper.loop(Looper.java:130)
  09-06 19:12:36.550: E/AndroidRuntime(14116):  at android.app.ActivityThread.main(ActivityThread.java:3686)
 09-06 19:12:36.550: E/AndroidRuntime(14116):   at java.lang.reflect.Method.invokeNative(Native Method)
 09-06 19:12:36.550: E/AndroidRuntime(14116):   at java.lang.reflect.Method.invoke(Method.java:507)
 09-06 19:12:36.550: E/AndroidRuntime(14116):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 09-06 19:12:36.550: E/AndroidRuntime(14116):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 09-06 19:12:36.550: E/AndroidRuntime(14116):   at dalvik.system.NativeStart.main(Native Method)