Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 致命错误:单击按钮时无法将类强制转换为其他类_Java_Android_Android Gradle Plugin_Android Multidex - Fatal编程技术网

Java 致命错误:单击按钮时无法将类强制转换为其他类

Java 致命错误:单击按钮时无法将类强制转换为其他类,java,android,android-gradle-plugin,android-multidex,Java,Android,Android Gradle Plugin,Android Multidex,我正试图在我的项目中使用Android Skype SDK,但我收到一个错误,说无法执行方法OnClick。SkypeActivity.class无法强制转换为S4BDemoApplication.class 我猜是我的S4BDemoApplication.class中的这部分代码: @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDe

我正试图在我的项目中使用Android Skype SDK,但我收到一个错误,说
无法执行方法OnClick。SkypeActivity.class无法强制转换为S4BDemoApplication.class

我猜是我的S4BDemoApplication.class中的这部分代码:

@Override
protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
}
MultiDex.install(this)
可能导致问题,因为我的gradle中没有包含任何
dexOptions

我确实有它们,但当我试着运行它时,我得到一个错误,说

没有这样的属性 所以我不得不在我的gradle中对它们进行评论,效果很好

你认为这是错误的原因吗?有解决办法吗

我的gradle文件

apply plugin: 'com.android.application'

def ROOTDIR     = file("..").absolutePath

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'


defaultConfig {
    applicationId "it.moondroid.chatbot"
    minSdkVersion 17
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

buildTypes {
    debug {
        minifyEnabled false
        debuggable true
        jniDebuggable true
    }

    release {
        debuggable true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/MSFTSIG.RSA'
        exclude 'META-INF/BCKEY.DSA'
        exclude 'META-INF/BCKEY.SF'
        exclude 'META-INF/MSFTSIG.SF'
    }

    dexOptions {
      //  preDexLibraries=false
      //  jumboMode = true
      //  javaMaxHeapSize "4g"
    }
}

configurations {
    all*. exclude group: 'com.android.support', module: 'support-v4'
    all*. exclude group: 'com.android.support', module: 'support-annotations'
}

productFlavors {
}
}

dependencies {

compile 'com.android.support:multidex:1.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile files('libs/sanmoku-0.0.5.jar')
compile files('libs/joda-time-2.1.jar')
compile(name: "libucmp", ext: 'aar')
compile(name: "platform", ext: 'aar')
compile(name: "injector", ext: 'aar')
compile(name: "SkypeForBusiness", ext: 'aar')
compile(name: "ucmp-enums", ext: 'aar')
compile(name: "TelemetryClient2", ext: 'aar')
compile(name: "TelemetryService", ext: 'aar')
compile(name: "android-database-sqlcipher", ext: 'aar')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
}
错误

致命异常:主 进程:it.moondroid.chatbot,PID:20952 主题:主题:{default=overlay:system,iconPack:system,fontPkg:system,com.android.systemui=overlay:system,com.android.systemui.navbar=overlay:system} java.lang.IllegalStateException:无法为android执行方法:onClick 在android.view.view$DeclaredOnClickListener.onClick(view.java:4458) 在android.view.view.performClick上(view.java:5204) 在android.view.view$PerformClick.run(view.java:21158) 位于android.os.Handler.handleCallback(Handler.java:739) 位于android.os.Handler.dispatchMessage(Handler.java:95) 位于android.os.Looper.loop(Looper.java:148) 位于android.app.ActivityThread.main(ActivityThread.java:5461) 位于java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:726) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 原因:java.lang.reflect.InvocationTargetException 位于java.lang.reflect.Method.invoke(本机方法) 在android.view.view$DeclaredOnClickListener.onClick(view.java:4453) 在android.view.view.performClick上(view.java:5204) 在android.view.view$PerformClick.run(view.java:21158) 位于android.os.Handler.handleCallback(Handler.java:739) 位于android.os.Handler.dispatchMessage(Handler.java:95) 位于android.os.Looper.loop(Looper.java:148) 位于android.app.ActivityThread.main(ActivityThread.java:5461) 位于java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:726) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 原因:java.lang.ClassCastException:it.moondroid.chatbot.ChatBotApplication无法强制转换为它。moondroid.chatbot.SFBDemoApplication 点击it.moondroid.chatbot.SkypeActivity.onjoinmeetingbutton(SkypeActivity.java:143) 位于java.lang.reflect.Method.invoke(本机方法) 在android.view.view$DeclaredOnClickListener.onClick(view.java:4453) 在android.view.view.performClick上(view.java:5204) 在android.view.view$PerformClick.run(view.java:21158) 位于android.os.Handler.handleCallback(Handler.java:739) 位于android.os.Handler.dispatchMessage(Handler.java:95) 位于android.os.Looper.loop(Looper.java:148) 位于android.app.ActivityThread.main(ActivityThread.java:5461) 位于java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit$MethodAndArgsC上
package it.moondroid.chatbot;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.TextView;

import com.microsoft.office.sfb.appsdk.AnonymousSession;
import com.microsoft.office.sfb.appsdk.Application;
import com.microsoft.office.sfb.appsdk.ConfigurationManager;
import com.microsoft.office.sfb.appsdk.Conversation;
import com.microsoft.office.sfb.appsdk.DevicesManager;
import com.microsoft.office.sfb.appsdk.Observable;
import com.microsoft.office.sfb.appsdk.SFBException;

import java.net.URI;

/**
 * Main Activity of the app.
 * The activity provides UI to join the meeting and navigate to the conversations view.
 */
public class SkypeActivity extends AppCompatActivity {

    Application application = null;
    ConfigurationManager configurationManager = null;
    DevicesManager devicesManager = null;
    ConversationPropertyChangeListener conversationPropertyChangeListener = null;
    Conversation anonymousConversation = null;
    AnonymousSession anonymousSession = null;
    TextView conversationStateTextView = null;
    Button joinMeetingButton = null;

    private Intent conversationsIntent = null;
boolean meetingJoined = false;

/**
 * Creating the activity initializes the SDK Application instance.
 * @param savedInstanceState saved instance.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_skype);

    this.application = Application.getInstance(this.getApplication().getApplicationContext());
    this.devicesManager = application.getDevicesManager();
    this.configurationManager = application.getConfigurationManager();

    // This flag will enable certain features that are in preview mode.
    // E.g. Audio / Video capability OnPrem topologies.
    this.configurationManager.enablePreviewFeatures(true);

    // Note that the sample enable video over cellular network. This is not the default.
    this.configurationManager.setRequireWiFiForVideo(false);

    // Max video channel count needs to be set to view video for more than one participant.
    this.configurationManager.setMaxVideoChannelCount(5);

    // Get UI elements.
    this.conversationStateTextView = (TextView)findViewById(R.id.statusTextViewId);
    this.joinMeetingButton = (Button)findViewById(R.id.joinMeetingButtonId);
    this.conversationsIntent = new Intent(this,ConversationsActivity.class);

    this.updateUiState();
}

@Override
protected void onDestroy() {
    this.configurationManager = null;
    this.application = null;

    super.onDestroy();
}

/**
 * Navigate to the conversations list view.
 * Note that, the conversations list view is provided only for demonstration purposes.
 * For anonymous meeting join it will always have a single conversation after meeting join is
 * successful.
 * @param view View
 */
public void onConversationsButtonClick(android.view.View view) {
    this.navigateToConversationsActivity();
}

/**
 * The click handler joins or leaves the meeting based on current state.
 *
 * @param view View.
 */
public void onJoinMeetingButtonClick(android.view.View view) {
    // Hide keyboard
    InputMethodHelper.hideSoftKeyBoard(this.getApplication().getApplicationContext(),
            view.getWindowToken());

    if (meetingJoined) {
        // Leave the meeting.
        try {
            this.anonymousConversation.leave();
            this.meetingJoined = false;
            this.updateUiState();

        } catch (SFBException e) {
            e.printStackTrace();
        }
    } else {
        //Join the meeting.
        // Get the display name.
        final android.widget.TextView displayNameTextView =
                (android.widget.TextView) findViewById(R.id.displayNameEditTextId);

        // Get the meeting uri
        final android.widget.EditText joinMeetingEditText =
                (android.widget.EditText) findViewById(R.id.meetingUriEditTextId);
        String meetingUriString = joinMeetingEditText.getText().toString();
        URI meetingUri = URI.create(meetingUriString);

        // Join meeting and monitor conversation state to determine meeting join completion.
        try {

            // Set the default device to Speaker
            //this.devicesManager.setActiveEndpoint(DevicesManager.Endpoint.LOUDSPEAKER);

            this.anonymousSession = this.application.joinMeetingAnonymously(
                    displayNameTextView.getText().toString(), meetingUri);

            this.anonymousConversation = this.anonymousSession.getConversation();
            SFBDemoApplication application = (SFBDemoApplication)getApplication();
            application.setAnonymousConversation(this.anonymousConversation);

            // Conversation begins in Idle state. It will move from Idle->Establishing->InLobby/Established
            // depending on meeting configuration.
            // We will monitor property change notifications for State property.
            // Once the conversation is Established, we will move to the next activity.
            this.conversationPropertyChangeListener = new ConversationPropertyChangeListener();
            this.anonymousConversation.addOnPropertyChangedCallback(this.conversationPropertyChangeListener);
        } catch (SFBException e) {
            e.printStackTrace();
        }
    }
}

/**
 * Update the UI state.
 */
public void updateUiState() {
    if (meetingJoined) {
        this.joinMeetingButton.setText(R.string.leave_meeting);
    } else {
        this.joinMeetingButton.setText(R.string.join_meeting);
        //conversationStateTextView.setText("");
    }
}

/**
 * Navigate to the Conversations activity.
 */
private void navigateToConversationsActivity() {
    startActivity(this.conversationsIntent);
}

/**
 * Determines meeting join state based on conversations state.
 */
public void updateConversationState() {
    Conversation.State state = this.anonymousConversation.getState();
    conversationStateTextView.setText(state.toString());
    switch (state) {
        case ESTABLISHED:
            this.meetingJoined = true;
            break;
        case IDLE:
            conversationStateTextView.setText("");
            this.meetingJoined = false;
            if (this.anonymousConversation != null) {
                this.anonymousConversation.removeOnPropertyChangedCallback(this.conversationPropertyChangeListener);
                this.anonymousConversation = null;
            }
            break;
        default:
    }

    // Refresh the UI
    this.updateUiState();

    if (meetingJoined) {
        this.navigateToConversationsActivity();
    }
}

/**
 * Helper method to show alerts.
 * @param message Alert message.
 */
private void showAlert(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(message);
    builder.show();
}

/**
 * Callback implementation for listening for conversation property changes.
 */
class ConversationPropertyChangeListener extends Observable.OnPropertyChangedCallback {
    /**
     * onProperty changed will be called by the Observable instance on a property change.
     *
     * @param sender     Observable instance.
     * @param propertyId property that has changed.
     */
    @Override
    public void onPropertyChanged(Observable sender, int propertyId) {
        if (propertyId == Conversation.STATE_PROPERTY_ID) {
            updateConversationState();
        }
    }
}
}
package it.moondroid.chatbot;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

import com.microsoft.office.sfb.appsdk.Conversation;

/**
 * Demo Application class
 */
public class SFBDemoApplication extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
         MultiDex.install(this);
    }

    /**
     * Saving the anonymous conversation to be shared across activities.
     */
    private Conversation anonymousConversation = null;

    /**
     * Save the anonymous conversation.
     * @param conversation
     */
    public void setAnonymousConversation(Conversation conversation) {
        this.anonymousConversation = conversation;
    }

    /**
     * Get the anonymous conversation.
     * @return Conversation conversation.
     */
    public Conversation getAnonymousConversation() {
        return this.anonymousConversation;
    }

}
<application android:name='.SFBDemoApplication" >