尝试连接 sphero 时出错

Posted

技术标签:

【中文标题】尝试连接 sphero 时出错【英文标题】:An error occurred while trying to connect with the sphero 【发布时间】:2014-07-19 15:59:06 【问题描述】:

有人能识别出这段代码的错误吗,程序本身的逻辑没有实现,它应该只是连接球体,那么应该不会发生错误。 有谁知道如何解决这个问题

提前谢谢你。

public class MainActivitySimon extends Activity 

    private SpheroConnectionView mSpheroConnectionView;
    private Sphero mRobot = null;

    private void updateSpheroPosition(double x, double y)
    
    

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity_simon);

        mSpheroConnectionView = (SpheroConnectionView)     findViewById(R.id.sphero_connection_view);
        mSpheroConnectionView.addConnectionListener(new ConnectionListener() 
        

            @Override
            public void onConnected(Robot robot) 
            
                //SpheroConnectionView is made invisible on connect by default
                mRobot = (Sphero) robot;
            

            @Override
            public void onConnectionFailed(Robot sphero) 
            
                // let the SpheroConnectionView handle or hide it and do something here
            

            @Override
            public void onDisconnected(Robot sphero) 
            
                mSpheroConnectionView.startDiscovery();
            
        );
    

    @Override
    protected void onResume()
    
        super.onResume();
        mSpheroConnectionView.startDiscovery();
     
    @Override
    protected void onPause() 
    
        super.onPause();
        RobotProvider.getDefaultProvider().disconnectControlledRobots();
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    
        getMenuInflater().inflate(R.menu.activity_main_activity_simon, menu);
        return true;
    


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/R"
    android:layout_
    android:layout_
    android:background="#262625"
    android:paddingBottom="5dp"
    tools:context=".MainActivitySimon" >

<Button
    android:id="@+id/Green"
    android:layout_
    android:layout_
    android:layout_alignRight="@+id/Red"
    android:layout_alignTop="@+id/Yellow"
    android:background="@drawable/customgreen"/>

<Button
    android:id="@+id/Yellow"
    android:layout_
    android:layout_
    android:layout_alignLeft="@+id/Blue"
    android:layout_below="@+id/Blue"
    android:background="@drawable/customyellow"
    android:layout_marginTop = "3dp" />


<TextView
    android:id="@+id/Scorebox"
    android:layout_
    android:layout_
    android:layout_alignRight="@+id/Yellow"
    android:layout_below="@+id/Yellow"
    android:layout_marginTop="8dp"
    android:text="Current Score: "
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#cccccc"
    android:textColorLink="#262625" />

<TextView
    android:id="@+id/info"
    android:layout_
    android:layout_
    android:layout_alignBottom="@+id/Scorebox"
    android:layout_alignLeft="@+id/Green"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#cccccc" />

<Button
    android:id="@+id/Red"
    android:layout_
    android:layout_
    android:layout_above="@+id/Simon"
    android:layout_toLeftOf="@+id/Simon"
    android:layout_marginRight = "-50dip"
    android:layout_marginBottom = "-30dip"
    android:background="@drawable/custombuttons" />

        <Button
            android:id="@+id/Blue"
            android:layout_
            android:layout_
            android:layout_alignBaseline="@+id/Red"
            android:layout_alignBottom="@+id/Red"
            android:layout_toRightOf="@+id/Simon"
            android:layout_marginLeft = "-50dip"
            android:background="@drawable/customblue" />

        <Button
            android:id="@+id/Simon"
            android:layout_
            android:layout_
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@drawable/customsimon"
            android:onClick="Simonsays" />

      <orbotix.view.connection.SpheroConnectionView
            android:id="@+id/sphero_connection_view"
            android:layout_
            android:layout_
            android:background="#D0000000"/>


</RelativeLayout>

    07-19 12:03:50.354: E/AndroidRuntime(23914): FATAL EXCEPTION: Thread-9923
    07-19 12:03:50.354: E/AndroidRuntime(23914): Process: com.hprc.simongame, PID: 23914
    07-19 12:03:50.354: E/AndroidRuntime(23914): java.lang.UnsatisfiedLinkError:       Couldn't load achievement_manager from loader dalvik.system.PathClassLoader[DexPathList[[zip   file "/data/app/com.hprc.simongame-1.apk"],nativeLibraryDirectories=[/data/app- lib/com.hprc.simongame-1, /vendor/lib, /system/lib]]]: findLibrary returned null
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at  java.lang.Runtime.loadLibrary(Runtime.java:358)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at java.lang.System.loadLibrary(System.java:526)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at orbotix.achievement.AchievementManager.<clinit>(AchievementManager.java:110)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at orbotix.robot.internal.DeviceConnection$DeviceSession$1$1.handleMessage(DeviceConnection.java:765)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at android.os.Handler.dispatchMessage(Handler.java:102)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at android.os.Looper.loop(Looper.java:136)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at orbotix.robot.internal.DeviceConnection$DeviceSession$1.run(DeviceConnection.java:787)
    07-19 12:03:50.354: E/AndroidRuntime(23914):    at java.lang.Thread.run(Thread.java:841)
    07-19 12:03:50.876: E/ActivityThread(23914): Activity com.hprc.simongame.MainActivitySimon has leaked IntentReceiver orbotix.robot.base.RobotProvider$1@41ff37d8 that was originally registered here. Are you missing a call to unregisterReceiver()?
    07-19 12:03:50.876: E/ActivityThread(23914): android.app.IntentReceiverLeaked: Activity com.hprc.simongame.MainActivitySimon has leaked IntentReceiver orbotix.robot.base.RobotProvider$1@41ff37d8 that was originally registered here. Are you missing a call to unregisterReceiver()?
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:805)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:606)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1559)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1539)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1533)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:467)
    07-19 12:03:50.876: E/ActivityThread(23914):    at orbotix.robot.base.RobotProvider.setBroadcastContext(RobotProvider.java:209)
    07-19 12:03:50.876: E/ActivityThread(23914):    at orbotix.robot.base.RobotProvider.startDiscovery(RobotProvider.java:236)
    07-19 12:03:50.876: E/ActivityThread(23914):    at orbotix.view.connection.SpheroConnectionView.setupConnectionView(SpheroConnectionView.java:254)
    07-19 12:03:50.876: E/ActivityThread(23914):    at orbotix.view.connection.SpheroConnectionView.startDiscovery(SpheroConnectionView.java:247)
    07-19 12:03:50.876: E/ActivityThread(23914):    at orbotix.view.connection.SpheroConnectionView.<init>(SpheroConnectionView.java:215)
    07-19 12:03:50.876: E/ActivityThread(23914):    at java.lang.reflect.Constructor.constructNative(Native Method)
    07-19 12:03:50.876: E/ActivityThread(23914):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    07-19 12:03:50.876: E/ActivityThread(23914):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.Activity.setContentView(Activity.java:1937)
    07-19 12:03:50.876: E/ActivityThread(23914):    at com.hprc.simongame.MainActivitySimon.onCreate(MainActivitySimon.java:81)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.Activity.performCreate(Activity.java:5248)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ActivityThread.access$800(ActivityThread.java:139)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.os.Handler.dispatchMessage(Handler.java:102)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.os.Looper.loop(Looper.java:136)
    07-19 12:03:50.876: E/ActivityThread(23914):    at android.app.ActivityThread.main(ActivityThread.java:5086)
    07-19 12:03:50.876: E/ActivityThread(23914):    at java.lang.reflect.Method.invokeNative(Native Method)
    07-19 12:03:50.876: E/ActivityThread(23914):    at java.lang.reflect.Method.invoke(Method.java:515)
    07-19 12:03:50.876: E/ActivityThread(23914):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    07-19 12:03:50.876: E/ActivityThread(23914):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    07-19 12:03:50.876: E/ActivityThread(23914):    at dalvik.system.NativeStart.main(Native Method)

【问题讨论】:

【参考方案1】:

评论有点晚了。但是因为我也花了很多时间寻找这个答案,所以我会在这里发布我的解决方案。我希望遇到这个问题的人现在可以解决它。

如果您使用的是android studio,只需将armeabiarmeabi-v7a复制到src/main/jniLibs/

【讨论】:

【参考方案2】:

问题仅与导入库有关,解决只需将所有文件夹内容 Sphero-Android-SDK/library/libs 复制到项目目标中的 libs 文件夹即可。并清理项目。

【讨论】:

以上是关于尝试连接 sphero 时出错的主要内容,如果未能解决你的问题,请参考以下文章

Unity 4.3.4 + Sphero 插件在使用包含的示例场景时崩溃

增强现实的 SPHERO

有没有办法在android中自动连接Sphero

智能手机“进入睡眠状态”时与 Sphero 的蓝牙连接丢失

如何开始使用 C# 开发 Sphero-Ball Windows 应用程序?

连接到 Sphero sprk+ android