简体   繁体   English

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

[英]Error while running the App for the first time can not cast issue

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)

The Problem is, that I have no idea, what the exact solution is. 问题是,我不知道确切的解决方案是什么。 I've tried a lot of "solutions" from this page, but maybe I'm to stupid to resolve that problem. 我已经尝试过此页面上的许多“解决方案”,但也许我很愚蠢以解决该问题。 If there are any request for some Code, please ask. 如果有任何要求提供某些代码的要求,请询问。

Thanks for your help! 谢谢你的帮助!

The requested Class (shortened) 要求的班级(缩短)

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

And the cast: 和演员:

<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>

My updated Manifest 我更新的清单

<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>

here my ApplicationClass.java 这是我的ApplicationClass.java

public class ApplicationClass extends Application{

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

} }

以android名称命名-在Manifest.xml中,您拥有此MyWoofiApplication_但仅需要此MyWoofiApplication对吗?

you have this line in manifest: 您在清单中有这一行:

<application
    android:name=".MyWoofiApplication_"

so MyWoofiApplication_ should extends android.app.Application but it did not so you have this exception: 因此MyWoofiApplication_应该扩展android.app.Application但没有扩展,因此您遇到了以下异常:

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

Application need to extends Application and mentioned in Manifest file & MainActivity extends Activity 应用程序需要扩展Application并在清单文件中提到,MainActivity扩展Activity

You got error because your MyWoofiApplication_ is not extend Application it's extend Activity so got that's why you got this error: 因为您的MyWoofiApplication_不是扩展应用程序,而是扩展活动,所以出现了错误,所以这就是您收到此错误的原因:

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

Application Class 应用类别

public class ApplicationClass extends Application {

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

Manifest File 清单文件

<?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 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);       
    }
 }

Hope you understand now and it may help to you. 希望您现在就明白了,对您有所帮助。

MyWoofiApplication_ is extending Activity so you can not cast it to Application. MyWoofiApplication_正在扩展Activity,因此您无法将其强制转换为Application。

You can remove android:name=".MyWoofiApplication_" from your application tag to resolve your issue. 您可以从应用程序标记中删除android:name =“。MyWoofiApplication_”来解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM