Android服务android.os.BinderProxy错误 - java

我一直在尝试使此android服务正常工作,但我不知道为什么会收到此错误。

05-13 12:13:36.203: ERROR/dalvikvm(7782): could not disable core file generation for   pid 7782: Operation not permitted
05-13 12:13:36.469: ERROR/AndroidRuntime(7782): FATAL EXCEPTION: main
05-13 12:13:36.469: ERROR/AndroidRuntime(7782): java.lang.ClassCastException: android.os.BinderProxy
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at whiskeymedia.com.GiantBombAppActivity$1.onServiceConnected(GiantBombAppActivity.java:69)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1064)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1081)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at android.os.Handler.handleCallback(Handler.java:587)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at android.os.Looper.loop(Looper.java:130)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at android.app.ActivityThread.main(ActivityThread.java:3806)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at java.lang.reflect.Method.invokeNative(Native Method)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at java.lang.reflect.Method.invoke(Method.java:507)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-13 12:13:36.469: ERROR/AndroidRuntime(7782):     at dalvik.system.NativeStart.main(Native Method)
05-13 12:13:45.234: ERROR/GlobalUnplugService(7116): plugged = true,mBatteryPlugged=true

GiantBombAppActivity:

package whiskeymedia.com;

import java.util.ArrayList;
import java.util.List;

import whiskeymedia.com.vo.Achievement;
import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class GiantBombAppActivity extends ListActivity {
  private ListView mListView;

  private AchievementDatabase achievementDatabase;

  private AchievementUpdateService s;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mListView = getListView();
    List<Achievement> achievements = new ArrayList<Achievement>();
    achievementDatabase = new AchievementDatabase(this);
    achievementDatabase.open();
    //achievementDatabase.resetDatabase();
    achievements = achievementDatabase.getAllAchievements();

    MyAdapter adapter = new MyAdapter(this, achievements);
    setListAdapter(adapter);

    List<String> achievementNames = new ArrayList<String>();
    for(Achievement achievement: achievements) {
      achievementNames.add(achievement.getAchievementName());

      mListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id){
          //When clicked show a toast with the textview text
          Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
      });

      doBindService();
    }
  }

  private ServiceConnection mConnection = new ServiceConnection() {

    public void onServiceConnected(ComponentName className, IBinder binder) {
      s = ((AchievementUpdateService.MyBinder) binder).getService();
      Toast.makeText(GiantBombAppActivity.this, "Connected", Toast.LENGTH_SHORT).show();
    }

    public void onServiceDisconnected(ComponentName className) {
      s = null;
    }
  };

  void doBindService() {
    bindService(new Intent(this, AchievementUpdateService.class), mConnection, Context.BIND_AUTO_CREATE);
  }

  /**
  * Adapter class to use for the list
  */
  private static class MyAdapter extends ArrayAdapter<Achievement> {

    /**
    * Constructor
    * 
    * @param context The context
    * @param contacts The list of contacts
    */
    public MyAdapter(final Context context, final List<Achievement> achievements) {
      super(context, 0, achievements);
    }

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
      View view = convertView;
      if (view == null) {
        view = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
      }

      final TextView achiev = (TextView)view.findViewById(R.id.achievement);
      if (getItem(position).getAchievmentRarity().compareTo("common") == 0) {
        achiev.setTextColor(Color.GREEN);
      }
      else if (getItem(position).getAchievmentRarity().compareTo("uncommon") == 0) {
        achiev.setTextColor(Color.BLUE);
      }
      else if (getItem(position).getAchievmentRarity().compareTo("rare") == 0) {
        achiev.setTextColor(Color.MAGENTA);
      }

      achiev.setText(getItem(position).getAchievementName());

      final TextView game = (TextView)view.findViewById(R.id.game);
      game.setText(getItem(position).getGameName());
        return view;
      }
    }
  }
}

成就更新服务:

package whiskeymedia.com;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import whiskeymedia.com.vo.Achievement;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class AchievementUpdateService extends Service{

  private AchievementDatabase achievementDatabase;

  private final IBinder mBinder = new MyBinder();

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    HtmlParser htmlParser = new HtmlParser();
    try {
      List<Achievement> achievements= htmlParser.parseDocument();
      achievementDatabase.loadAchievements(achievements);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    return Service.START_NOT_STICKY;
  }

  @Override
  public IBinder onBind(Intent arg0) {
    return mBinder;
  }

  public class MyBinder extends Binder {
    AchievementUpdateService getService() {
    return AchievementUpdateService.this;
    }
  }

}

知道我在做什么错吗?

参考方案

崩溃是因为您要返回的活页夹是BinderProxy的实例,而不是本地活页夹类。通常会发生这种情况,因为您的活动试图绑定到不在同一进程中的服务。跨流程边界绑定时,将使用BinderProxy实例代替实际实例(因为它在不同的流程中)。

您的AndroidManifest.xml是什么样的?

绑定Java库Xamarin.Android - java

我花了两天时间在每个论坛,文档,tuto,博客等上寻找答案。我为实习生启动了一个Android应用程序,因为我不懂Java,所以用xamarin C#开发了它。直到最近一切都还不错,但现在我需要集成一个SDK才能在应用程序中使用POS(销售点),但是该库是用Java编写的,即使跟随文档或辅导老师,我也无法将其与xamarin绑定(我什至无法调试)。这里有人已…

OpenJDK7 OS X上的file.listFiles()在包含欧元符号的文件名上损坏 - java

似乎以下file.listFiles()在OS X的OpenJDK 7上已损坏。此代码段将打印“此文件带有欧元符号...不存在”。 final String pathname = System.getProperty("user.home") + "/folderThatContainsAFileWithTheEuroSymbo…

为什么我的应用在启动时总是崩溃-Android - java

刚刚遵循了有关如何制作按钮和活动的youtube指南。我按照他的代码减小字体大小,并且在启动时一直崩溃。有人知道为什么吗?public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { su…

如何在TabLayout中自定义选定的选项卡指示器? - java

我想更改带有自定义图标的TabLayout的所选标签指示器,该标签指示器应遵循相同的行为(当用户向下一个标签滑动时,图标将相应移动)。该类中没有默认方法,因为您只能实现选项卡的布局自定义。我决定看一下TabLayout的source code,但1)我无法在类中找到定义制表符指示器绘制时形状的定义的要点,以及2)我找不到甚至完全导入该类。我还希望-如果可能的…

在Android中以编程方式从启动器中删除应用程序 - java

有没有一种方法可以在运行时从家庭启动器中删除活动?我的意思是从其属性或类似内容中删除Intent.CATEGORY_LAUNCHER。 参考方案 您可以通过PackageManager#setComponentEnabledSetting()禁用组件,这将具有将其从启动器中删除的作用。