gpt4 book ai didi

java - 异常 android.support.multidex.MultiDexApplication 不能投类

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:45:10 25 4
gpt4 key购买 nike

我有一个问题,我的应用程序生成了这个异常,我不明白。我已经在我的 build.gradle 中实现了 multiDexEnabled

  Caused by: java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to com.example.AnalyticsApplication

我的类 Java

public class Splash extends Activity {

private Tracker mTracker;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);

//Analitycs
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
mTracker.setScreenName("Splash");
mTracker.send(new HitBuilders.ScreenViewBuilder().build());

文件 Gradle

 defaultConfig {
multiDexEnabled true
}

list .xml

<uses-permissionandroid:name="android.permission.INTERNET"/>
<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activityandroid:name=".Splash">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter></activity>
</application>

最佳答案

我认为您应该将 AnalyticsApplication 类扩展到您自己的类中,如下所示:

public class YourApplicationName extends AnalyticsApplication {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);

//Analitycs
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
mTracker.setScreenName("Splash");
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}

// Here you will enable Multidex
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(getBaseContext());
}

}

在此之后,您必须将 AndroidManifest.xml 文件更改为:

<application
android:name="path.to.YourApplicationName"
...

请查看此链接以获取更多信息:http://developer.android.com/reference/android/support/multidex/MultiDex.html

关于java - 异常 android.support.multidex.MultiDexApplication 不能投类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com