RuntimeException:“存根!”没有其他信息

时间:2018-06-25 12:48:22

标签: java android bluetooth

我正在尝试使用this library。我已经实现了所有回调并尝试启动服务器:

public class MasterActivity extends AppCompatActivity {

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

        createBluetoothServer();
    }

    void createBluetoothServer(){
        IBluetoothServer btServer = new BluetoothServer.Builder(this.getApplicationContext(),
                "EasyBtService", ParcelUuid.fromString(uuid))
                .build();

        if (btServer == null){
            Log.e(this.getClass().getCanonicalName(), "Failed to create server!");
        } else {
            // Block until a client connects.
            IBluetoothClient btClient = btServer.accept();
            // Set a data callback to receive data from the remote device.
            btClient.setDataCallback(new DataReceivedCallbackMaster());
            // Set a connection callback to be notified of connection changes.
            btClient.setConnectionCallback(new ConnectionCallbackMaster());
            // Set a data send callback to be notified when data is sent of fails to send.
            btClient.setDataSentCallback(new DataSentCallbackMaster());
            btClient.sendData("ServerGreeting", "Hello Client".getBytes());
            //We don't want to accept any other clients.
            btServer.disconnect();
        }
    }
}

在此行:

IBluetoothServer btServer = new BluetoothServer.Builder(this.getApplicationContext(),
                "EasyBtService", ParcelUuid.fromString(uuid))
                .build();

我遇到以下异常:

Process: XXX, PID: 28033
java.lang.RuntimeException: Unable to start activity ComponentInfo{XXX/XXX.Activities.MasterActivity}: java.lang.RuntimeException: Stub!

没有任何有用的反馈。该存根应该是什么意思?有没有人遇到过这样的事情并能够解决?

编辑:我正在添加gradle文件。 项目build.gradle:

buildscript {

    repositories {
        google()
        jcenter()
        maven { url "http://code.newtronlabs.com:8081/artifactory/libs-release-local" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "com.newtronlabs.android:plugin:2.0.0.alpha"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "http://code.newtronlabs.com:8081/artifactory/libs-release-local" }
    }
}

subprojects {
    apply plugin: 'com.newtronlabs.android'
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

和应用程序build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "XXX"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.newtronlabs.easybluetooth:easybluetooth:2.0.0'
}

1 个答案:

答案 0 :(得分:1)

在这种情况下,您想对库使用provided,以便一切顺利进行。您要在gradle文件中进行更改。

provided 'com.newtronlabs.easybluetooth:easybluetooth:2.0.0'