首次运行该应用程序时出现错误,无法投放问题

时间:2018-09-04 12:08:14

标签: android fatal-error classcastexception runtimeexception

E/AndroidRuntime: FATAL EXCEPTION: main Process: de.mywoofi.app, PID: 17970 java.lang.RuntimeException: Unable to instantiate application de.mywoofi.app.MyWoofiApplication_: java.lang.ClassCastException: de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application at android.app.LoadedApk.makeApplication(LoadedApk.java:1069) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842) at android.app.ActivityThread.access$1100(ActivityThread.java:199) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.ClassCastException: de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50) at android.support.v4.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:49) at android.app.Instrumentation.newApplication(Instrumentation.java:1120) at android.app.LoadedApk.makeApplication(LoadedApk.java:1061) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842) at android.app.ActivityThread.access$1100(ActivityThread.java:199) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

问题是,我不知道确切的解决方案是什么。 我已经尝试过此页面上的许多“解决方案”,但也许我很愚蠢以解决该问题。 如果有任何要求提供某些代码的要求,请询问。

感谢您的帮助!

请求的类(缩短了)

@EActivity(de.mywoofi.app.R.layout.activity_main)
public class MyWoofiApplication extends Activity
{ [...]
}

和演员:

<application
    android:name=".MyWoofiApplication_"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:replace="android:icon"
    android:fullBackupContent="true"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning">
    <activity
        android:name=".ui.activity.SplashActivity_"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.Full"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

我更新的清单

<application
    android:name=".ApplicationClass"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:replace="android:icon"
    android:fullBackupContent="true"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning">
    <activity
        android:name=".ui.activity.SplashActivity_"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.Full"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

这里是我的ApplicationClass.java

public class ApplicationClass extends Application{

@Override
public void onCreate(){
    super.onCreate();
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
    .detectAll()
    .penaltyLog()
    .build());
}

}

4 个答案:

答案 0 :(得分:0)

在android名称中-在Manifest.xml中,您拥有这个MyWoofiApplication_,但是您只需要这个MyWoofiApplication是吗?

答案 1 :(得分:0)

清单中有此行:

<application
    android:name=".MyWoofiApplication_"

所以MyWoofiApplication_应该扩展android.app.Application,但是没有扩展,所以您有以下例外情况:

de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application

答案 2 :(得分:0)

  

应用程序需要扩展应用程序并在清单文件中提到   &MainActivity扩展了活动

您收到错误消息是因为您的MyWoofiApplication_不是扩展应用程序,而是扩展了活动,所以这就是您收到此错误的原因:

de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application

应用程序类

public class ApplicationClass extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="YOUR_PACKAGE_NAME">

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

    <application
        android:name=".ApplicationClass"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"
            android:windowSoftInputMode="adjustResize" />
    </application>

MainActivity.java

public class MainActivity extends Activity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        setContentView(R.layout.activity_main);       
    }
 }

希望您现在了解了,它可能会对您有所帮助。

答案 3 :(得分:0)

MyWoofiApplication_正在扩展Activity,因此您不能将其强制转换为Application。

您可以从应用程序标记中删除 android:name =“。MyWoofiApplication _” ,以解决您的问题。