2014-12-08 58 views
2

我在学习如何使用TokBox SDK。我只是开始写一个简单的应用程序来显示视频,以便我可以了解它的工作原理。我在https://tokbox.com/opentok/tutorials/connect-session/android/#connecting上找到的示例基于我的代码。但是,每次我初始化Session对象时,我的应用程序都停止工作。我尝试用try/catch块来围绕它,它仍然崩溃。我的代码如下:Opentok应用程序在声明会话时崩溃

package com.example.ben.toktest; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.RelativeLayout; 

import com.opentok.android.Session; 

public class MainActivity extends Activity{ 
    private static final String API_KEY= "12345678"; //replaced api key with 12345678 for privacy purposes 
    RelativeLayout container; 
    Session session; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     container = (RelativeLayout) findViewById(R.id.main); 

     session = new Session(MainActivity.this, "12345678", "2_MX40NTEwMjczMn5-MTQxODAyMDUwMjgwMn5PTjdlRDBvSDVYOHBkelZjby80eGZuclN-fg"); //Crashes here 
     /*session.setSessionListener(new Session.SessionListener() { 
      @Override 
      public void onConnected(Session session) { 

      } 

      @Override 
      public void onDisconnected(Session session) { 

      } 

      @Override 
      public void onStreamReceived(Session session, Stream stream) { 
       mStreams.add(stream); 
       subscriber = new Subscriber(MainActivity.this, stream); 
       subscriber.setSubscriberListener(new SubscriberListener() { 
        @Override 
        public void onConnected(SubscriberKit subscriberKit) { 
         LayoutParams params = new LayoutParams(getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels); 
         container.addView(subscriberKit.getView(), params); 
        } 

        @Override 
        public void onDisconnected(SubscriberKit subscriberKit) { 

        } 

        @Override 
        public void onError(SubscriberKit subscriberKit, OpentokError opentokError) { 

        } 
       }); 
       session.subscribe(subscriber); 

      } 

      @Override 
      public void onStreamDropped(Session session, Stream stream) { 

      } 

      @Override 
      public void onError(Session session, OpentokError opentokError) { 

      } 
     });*/ 

    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

从我logcat的输出是:

12-08 17:35:37.240 13677-13677/com.example.ben.toktest W/ActivityThread﹕ Application com.example.ben.toktest is waiting for the debugger on port 8100... 
12-08 17:35:37.250 13677-13677/com.example.ben.toktest I/System.out﹕ Sending WAIT chunk 
12-08 17:35:37.355 13677-13684/com.example.ben.toktest I/dalvikvm﹕ Debugger is active 
12-08 17:35:37.455 13677-13677/com.example.ben.toktest I/System.out﹕ Debugger has connected 
12-08 17:35:37.455 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:37.655 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:37.855 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:38.055 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:38.255 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:38.455 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:38.655 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:38.855 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:39.060 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:39.260 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:35:39.460 13677-13677/com.example.ben.toktest I/System.out﹕ debugger has settled (1374) 
12-08 17:35:40.105 13677-13677/com.example.ben.toktest W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/opentok/android/Session; 
12-08 17:35:40.105 13677-13677/com.example.ben.toktest D/AndroidRuntime﹕ Shutting down VM 
12-08 17:35:40.105 13677-13677/com.example.ben.toktest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40edb2a0) 
12-08 17:35:40.205 13677-13677/com.example.ben.toktest E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    java.lang.ExceptionInInitializerError 
      at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22) 
      at android.app.Activity.performCreate(Activity.java:5206) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
      at android.app.ActivityThread.access$600(ActivityThread.java:140) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
      at android.os.Handler.dispatchMessage(Handler.java:99) 
      at android.os.Looper.loop(Looper.java:137) 
      at android.app.ActivityThread.main(ActivityThread.java:4898) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:511) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opentok: findLibrary returned null 
      at java.lang.Runtime.loadLibrary(Runtime.java:365) 
      at java.lang.System.loadLibrary(System.java:535) 
      at com.opentok.android.Session.<clinit>(Session.java:46) 
            at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22) 
            at android.app.Activity.performCreate(Activity.java:5206) 
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
            at android.app.ActivityThread.access$600(ActivityThread.java:140) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:137) 
            at android.app.ActivityThread.main(ActivityThread.java:4898) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:511) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
            at dalvik.system.NativeStart.main(Native Method) 
12-08 17:36:01.010 14367-14367/com.example.ben.toktest W/ActivityThread﹕ Application com.example.ben.toktest is waiting for the debugger on port 8100... 
12-08 17:36:01.020 14367-14367/com.example.ben.toktest I/System.out﹕ Sending WAIT chunk 
12-08 17:36:01.070 14367-14373/com.example.ben.toktest I/dalvikvm﹕ Debugger is active 
12-08 17:36:01.220 14367-14367/com.example.ben.toktest I/System.out﹕ Debugger has connected 
12-08 17:36:01.220 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:01.420 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:01.620 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:01.820 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:02.020 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:02.225 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:02.425 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:02.630 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:02.845 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle... 
12-08 17:36:03.045 14367-14367/com.example.ben.toktest I/System.out﹕ debugger has settled (1459) 
12-08 17:36:03.395 14367-14367/com.example.ben.toktest W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/opentok/android/Session; 
12-08 17:36:03.400 14367-14367/com.example.ben.toktest D/AndroidRuntime﹕ Shutting down VM 
12-08 17:36:03.400 14367-14367/com.example.ben.toktest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40edb2a0) 
12-08 17:36:03.425 14367-14367/com.example.ben.toktest E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    java.lang.ExceptionInInitializerError 
      at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22) 
      at android.app.Activity.performCreate(Activity.java:5206) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
      at android.app.ActivityThread.access$600(ActivityThread.java:140) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
      at android.os.Handler.dispatchMessage(Handler.java:99) 
      at android.os.Looper.loop(Looper.java:137) 
      at android.app.ActivityThread.main(ActivityThread.java:4898) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:511) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opentok: findLibrary returned null 
      at java.lang.Runtime.loadLibrary(Runtime.java:365) 
      at java.lang.System.loadLibrary(System.java:535) 
      at com.opentok.android.Session.<clinit>(Session.java:46) 
            at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22) 
            at android.app.Activity.performCreate(Activity.java:5206) 
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083) 
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125) 
            at android.app.ActivityThread.access$600(ActivityThread.java:140) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:137) 
            at android.app.ActivityThread.main(ActivityThread.java:4898) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:511) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
            at dalvik.system.NativeStart.main(Native Method) 

有人能告诉我为什么它总是崩溃?我不知道我做错了什么!

回答

9

尝试使用Android Studio运行OpenTok示例应用程序时,我遇到了同样的问题。

试试这个:

1)打开你的应用程序/文件的build.gradle并添加行

编译文件( '库/ opentok-Android的SDK-2.2.1.jar')

依赖项下。

2)创建一个文件夹您的应用程序文件夹下(如果它尚不存在)

3)复制OpenTok JAR文件(opentok-Android的SDK-2.3.1.jar)在OpenTok SDK库文件夹到你应用程序/库文件夹

4)创建的文件夹jniLibs下的应用程序/ src目录/主/

5)复制文件夹armeabix86,从OpenTok SDK libs文件夹复制到jniLibs文件夹,然后运行您的应用程序。

我希望它有帮助!

+0

这实际上工作!谢谢。可惜的是,Android Studio仍然要求我们以这样一种循环的方式来做事。 – 2014-12-16 01:45:51

+0

谢谢,它的工作。 – 2015-01-14 08:30:19