一按計算結果的時候就報錯
04-11 02:39:02.488 2986-2986/com.example.wwq.aidlclient E/AndroidRuntime: FATAL EXCEPTION: main
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Process: com.example.wwq.aidlclient, PID: 2986
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? java.lang.NullPointerException: Attempt to invoke interface method 'int com.example.wwq.myapplication.IMyAidl.add(int, int)' on a null object reference
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at com.example.wwq.aidlclient.MainActivity.onClick(MainActivity.java:66)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at android.view.View.performClick(View.java:4780)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at android.view.View$PerformClick.run(View.java:19866)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at android.os.Handler.handleCallback(Handler.java:739)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at android.os.Handler.dispatchMessage(Handler.java:95)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at android.os.Looper.loop(Looper.java:135)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at android.app.ActivityThread.main(ActivityThread.java:5254)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at java.lang.reflect.Method.invoke(Native Method)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at java.lang.reflect.Method.invoke(Method.java:372)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
2016-07-02
? ?//調用遠程的服務
? ? ? ? ? ?int res= iMyAidl.add(num2, num1);
? ? ? ? ? ?mEtRes.setText(res);
出錯在? ?mEtRes.setText(res);這里。mEtRes.setText(res);中的res是一個int 類型,那么res值對應是values文件夾中的strings.xml里的值。
應該改為mEtRes.setText(res+“”);這樣就行了
2017-01-18
我也遇到這個問題。我解決了。
大家想一下,我們除了app ?module 之外,又建立了一個aidlclient module。那么我們運行的時候,應該安裝并啟動哪一個呢?現在一想,既然出現了編輯框和按鈕界面,那不是我們在aidlclient module編輯的頁面嗎?對呀。我們只安裝啟動了aidlclient module。也就是只要客戶端。
那么服務端跑哪里呢?想一下,是不是我們沒有安裝呢?對滴。
那么怎么確定自己安裝是那個module呢?看下圖:
2016-08-20
把app那個module先運行到手機上一次就可以了,手機上根本就沒有你要遠程調用的那個進程怎么調用。
2016-08-02
在服務端 注冊<service android:name=".AIDL"
? ?android:enabled="true"
? ?android:exported="true"></service>
2016-08-02
解決了沒有啊 啊啊啊,我也剛遇到這個問題
2016-08-02
解決了沒有啊 啊啊啊,我也剛遇到這個問題
2016-05-14
service 與activity一樣必須在AndroidManifest.xml里面注冊,因為你沒有注冊,肯定出錯了
2016-05-05
2016-04-26
package com.example.wwq.AidlClient;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.wwq.myapplication.IMyAidl;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
? ?private EditText mEtNum1;
? ?private EditText mEtNum2;
? ?private EditText mEtRes;
? ?private Button mBtnAdd;
? ?IMyAidl iMyAidl;
? ?private ServiceConnection conn = new ServiceConnection() {
? ? ? ?//綁定上服務的時候
? ? ? ?@Override
? ? ? ?public void onServiceConnected(ComponentName name, IBinder service) {
? ? ? ? //拿到了遠程的服務
? ? ? ? ?iMyAidl = ?IMyAidl.Stub.asInterface(service);
? ? ? ?}
? ? ? ?//斷開服務的時候
? ? ? ?@Override
? ? ? ?public void onServiceDisconnected(ComponentName name) {
? ? ? ? ? ?//回收資源
? ? ? ? ? ?iMyAidl = null;
? ? ? ?}
? ?};
? ?@Override
? ?protected void onCreate(Bundle savedInstanceState) {
? ? ? ?super.onCreate(savedInstanceState);
? ? ? ?setContentView(R.layout.activity_main);
? ? ? ?initView();
? ? ? ?//軟件一啟動就綁定服務
? ? ? ?bindService();
? ?}
? ?private void initView() {
? ? ? ?mEtNum1 = (EditText) findViewById(R.id.et_num1);
? ? ? ?mEtNum2 = (EditText) findViewById(R.id.et_num2);
? ? ? ?mEtRes = (EditText) findViewById(R.id.et_res);
? ? ? ?mBtnAdd = (Button) findViewById(R.id.btn_add);
? ? ? ?mBtnAdd.setOnClickListener(this);
? ?}
? ?@Override
? ?public void onClick(View v) {
? ? ? ?int num1 = Integer.parseInt(mEtNum1.getText().toString());
? ? ? int num2 = Integer.parseInt(mEtNum2.getText().toString());
? ? ? ?try {
? ? ? ? ? ?//調用遠程的服務
? ? ? ? ? ?int res= iMyAidl.add(num2, num1);
? ? ? ? ? ?mEtRes.setText(res);
? ? ? ?} catch (RemoteException e) {
? ? ? ? ? ?e.printStackTrace();
? ? ? ? ? ?mEtRes.setText("錯誤了");
? ? ? ?}
? ?}
? ?private void bindService() {
? ? ? ?//獲取到服務端
? ? ? ?Intent intent = new Intent();
? ? ? ?//新版本,必須 顯示intent啟動 綁定服務
? ? ? ?intent.setComponent(new ComponentName
? ? ? ? ? ? ? ?("com.example.wwq.myapplication","com.example.wwq.myapplication.IRemoteService"));
? ? ? ?bindService(intent,conn, Context.BIND_AUTO_CREATE);
? ?}
? ?@Override
? ?protected void onDestroy() {
? ? ? ?super.onDestroy();
? ? ? ?unbindService(conn);
? ?}
}
2016-04-25
服務端那個類的名字
包名+類名 ? 用.把前面的包名省略了