Android - java.lang.classcastexception-Fehler android.app.Anwendung kann nicht gegossen werden

Ich bin ein Android-Neuling, und ich Baue eine android-app über tutorial und ich möchte Spiel-features, die in es, ich habe bereits den Quellcode für das Spiel, und ich bereits importieren Sie alle Klassen in mein Projekt, aber wenn ich versuche, die app ausführen bekam ich eine Fehlermeldung, und es sagt "android.app.Anwendung java.lang.Classcastexception-Fehler können nicht umgewandelt werden, com.wglxy.Beispiel.dash1.ChuckApplication", ich nehme an, dass ist, weil ich fave 2-Aktivität genannt HomeActivity.java (Main) und ChuckApplication.java die (zweite) mit unterschiedlichen Ausprägungen (DashboardActivity & Application) ich weiß wirklich nicht, wie dieses Problem zu lösen, ich habe versucht,

  1. Machen das Spiel-Anwendung, die als Bibliothek(nicht arbeiten)
  2. Kombinieren die Tätigkeit (nicht Arbeit)
  3. ändern inten-filter > Kategorie (nicht arbeiten)

    aber es gibt nichts, Arbeit mit meinem Projekt

SplashActivity.java:

    import java.io.IOException;
    import java.util.List;

    import android.app.Activity;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.database.SQLException;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    import com.tmm.android.chuck.db.DBHelper;
    import com.tmm.android.chuck.quiz.Constants;
    import com.tmm.android.chuck.quiz.GamePlay;
    import com.tmm.android.chuck.quiz.Question;

    public class SplashActivity extends Activity implements OnClickListener{


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.welcome);

            //////////////////////////////////////////////////////////////////////
            ////////GAME MENU  /////////////////////////////////////////////////
            Button playBtn = (Button) findViewById(R.id.playBtn);
            playBtn.setOnClickListener(this);
            Button settingsBtn = (Button) findViewById(R.id.settingsBtn);
            settingsBtn.setOnClickListener(this);
            Button rulesBtn = (Button) findViewById(R.id.rulesBtn);
            rulesBtn.setOnClickListener(this);
            Button exitBtn = (Button) findViewById(R.id.exitBtn);
            exitBtn.setOnClickListener(this);
        }


        /**
         * Listener for game menu
         */
        @Override
        public void onClick(View v) {
            Intent i;

            switch (v.getId()){
            case R.id.playBtn :
                //once logged in, load the main page
                //Log.d("LOGIN", "User has started the game");

                //Get Question set //
                List<Question> questions = getQuestionSetFromDb();

                //Initialise Game with retrieved question set ///
                GamePlay c = new GamePlay();
                c.setQuestions(questions);
                c.setNumRounds(getNumQuestions());
                ((ChuckApplication)getApplication()).setCurrentGame(c);  

                //Start Game Now.. //
                i = new Intent(this, QuestionActivity.class);
                startActivityForResult(i, Constants.PLAYBUTTON);
                break;

            case R.id.rulesBtn :
                i = new Intent(this, RulesActivity.class);
                startActivityForResult(i, Constants.RULESBUTTON);
                break;

            case R.id.settingsBtn :
                i = new Intent(this, SettingsActivity.class);
                startActivityForResult(i, Constants.SETTINGSBUTTON);
                break;

            case R.id.exitBtn :
                finish();
                break;
            }

        }


        /**
         * Method that retrieves a random set of questions from
         * the database for the given difficulty
         * @return
         * @throws Error
         */
        private List<Question> getQuestionSetFromDb() throws Error {
            int diff = getDifficultySettings();
            int numQuestions = getNumQuestions();
            DBHelper myDbHelper = new DBHelper(this);
            try {
                myDbHelper.createDataBase();
            } catch (IOException ioe) {
                throw new Error("Unable to create database");
            }
            try {
                myDbHelper.openDataBase();
            }catch(SQLException sqle){
                throw sqle;
            }
            List<Question> questions = myDbHelper.getQuestionSet(diff, numQuestions);
            myDbHelper.close();
            return questions;
        }


        /**
         * Method to return the difficulty settings
         * @return
         */
        private int getDifficultySettings() {
            SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
            int diff = settings.getInt(Constants.DIFFICULTY, Constants.MEDIUM);
            return diff;
        }

        /**
         * Method to return the number of questions for the game
         * @return
         */
        private int getNumQuestions() {
            SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
            int numRounds = settings.getInt(Constants.NUM_ROUNDS, 20);
            return numRounds;
        }

    }

dies ist mein HomeActivity.java

/*
 * Copyright (C) 2011 Wglxy.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.wglxy.example.dash1;

import android.os.Bundle;

/**
 * This is a simple activity that demonstrates the dashboard user interface
 * pattern.
 *
 */

public class HomeActivity extends DashboardActivity
{

    /**
     * onCreate - called when the activity is first created. Called when the
     * activity is first created. This is where you should do all of your normal
     * static set up: create views, bind data to lists, etc. This method also
     * provides you with a Bundle containing the activity's previously frozen
     * state, if there was one.
     *
     * Always followed by onStart().
     *
     */

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
    }

    /**
     * onDestroy The final call you receive before your activity is destroyed.
     * This can happen either because the activity is finishing (someone called
     * finish() on it, or because the system is temporarily destroying this
     * instance of the activity to save space. You can distinguish between these
     * two scenarios with the isFinishing() method.
     *
     */

    protected void onDestroy()
    {
        super.onDestroy();
    }

    /**
     * onPause Called when the system is about to start resuming a previous
     * activity. This is typically used to commit unsaved changes to persistent
     * data, stop animations and other things that may be consuming CPU, etc.
     * Implementations of this method must be very quick because the next
     * activity will not be resumed until this method returns. Followed by
     * either onResume() if the activity returns back to the front, or onStop()
     * if it becomes invisible to the user.
     *
     */

    protected void onPause()
    {
        super.onPause();
    }

    /**
     * onRestart Called after your activity has been stopped, prior to it being
     * started again. Always followed by onStart().
     *
     */

    protected void onRestart()
    {
        super.onRestart();
    }

    /**
     * onResume Called when the activity will start interacting with the user.
     * At this point your activity is at the top of the activity stack, with
     * user input going to it. Always followed by onPause().
     *
     */

    protected void onResume()
    {
        super.onResume();
    }

    /**
     * onStart Called when the activity is becoming visible to the user.
     * Followed by onResume() if the activity comes to the foreground, or
     * onStop() if it becomes hidden.
     *
     */

    protected void onStart()
    {
        super.onStart();
    }

    /**
     * onStop Called when the activity is no longer visible to the user because
     * another activity has been resumed and is covering this one. This may
     * happen either because a new activity is being started, an existing one is
     * being brought in front of this one, or this one is being destroyed.
     *
     * Followed by either onRestart() if this activity is coming back to
     * interact with the user, or onDestroy() if this activity is going away.
     */

    protected void onStop()
    {
        super.onStop();
    }

    /**
     */
    //Click Methods

    /**
     */
    //More Methods

} //end class

dies ist mein ChuckApllicatiin:

/**
 *
 */
package com.wglxy.example.dash1;

import android.app.Application;

/**
 * @author rob
 *
 */
public class ChuckApplication extends Application
{
    private GamePlay currentGame;

    /**
     * @param currentGame
     *            the currentGame to set
     */
    public void setCurrentGame(GamePlay currentGame)
    {
        this.currentGame = currentGame;
    }

    /**
     * @return the currentGame
     */
    public GamePlay getCurrentGame()
    {
        return currentGame;
    }
}

dies ist mein manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wglxy.example.dash1"
    android:versionCode="1"
    android:versionName="1.0" >
    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/Theme.D1" >
        <activity
            android:name=".HomeActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Tutorial"
            android:label="@string/title_feature1"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Game"
            android:label="@string/title_feature2"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Setting"
            android:label="@string/title_feature3"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Qiblah"
            android:label="@string/title_feature4"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Takbir"
            android:label="@string/title_feature5"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Qiyam"
            android:label="@string/title_feature6"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Ruku"
            android:label="@string/title_feature7"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Sajdah"
            android:label="@string/title_feature8"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".SitBetw"
            android:label="@string/title_feature9"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Qunut"
            android:label="@string/title_feature10"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Tahiyyatul"
            android:label="@string/title_feature11"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Salam"
            android:label="@string/title_feature12"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Subuh"
            android:label="@string/title_feature13"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Dhuhur"
            android:label="@string/title_feature14"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Asr"
            android:label="@string/title_feature15"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Maghrib"
            android:label="@string/title_feature17"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Isha"
            android:label="@string/title_feature18"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Dhuha"
            android:label="@string/title_feature19"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Witir"
            android:label="@string/title_feature20"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Ied"
            android:label="@string/title_feature21"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Tarawih"
            android:label="@string/title_feature22"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Tahajud"
            android:label="@string/title_feature23"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".BasicMain"
            android:label="@string/title_feature23"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Fardh"
            android:label="@string/title_feature23"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Sunnah"
            android:label="@string/title_feature23"
            android:theme="@style/Theme.D1" />
        <activity
            android:name=".Dalil"
            android:label="@string/title_feature23"
            android:theme="@style/Theme.D1" />
        <!--
            <activity android:name=".AboutActivity"
                  android:theme="@style/Theme.D1"
                  android:label="@string/title_about"
                  />
            <activity android:name=".SearchActivity"
                  android:theme="@style/Theme.D1"
                  android:label="@string/title_search"
                  />
        -->
        <activity
            android:name=".SplashActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".QuestionActivity" />
        <activity android:name=".RulesActivity" />
        <activity android:name=".EndgameActivity" />
        <activity android:name=".SettingsActivity" />
        <activity android:name=".AnswersActivity" />
    </application>
    <uses-sdk android:minSdkVersion="11" />
    <tool-api-level>
        11
    </tool-api-level>
</manifest>

und dies ist mein LOG:

07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): FATAL EXCEPTION: main
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): java.lang.ClassCastException: android.app.Application cannot be cast to com.wglxy.example.dash1.ChuckApplication
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at com.wglxy.example.dash1.SplashActivity.onClick(SplashActivity.java: 57)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.view.View.performClick(View.java: 4202)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.view.View$PerformClick.run(View.java: 17340)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.os.Handler.handleCallback(Handler.java: 725)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.os.Handler.dispatchMessage(Handler.java: 92)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.os.Looper.loop(Looper.java: 137)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.app.ActivityThread.main(ActivityThread.java: 5039)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at java.lang.reflect.Method.invokeNative(Native Method)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at java.lang.reflect.Method.invoke(Method.java: 511)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 793)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 560)
07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at dalvik.system.NativeStart.main(Native Method)

weiß wer, wie zu beheben mein problem?

  • was ist in der Zeile SplashActivity.java:57
  • Poste bitte die relevanten Teile des Codes, in dem ein Fehler aufgetreten ist.
  • sorry, ich habe hinzufügen SplashActivity.java @MichaelShrestha dies ist Zeile 57 - codeGamePlay-c = new Spielverlauf();code
InformationsquelleAutor dzulfikar | 2013-07-10
Schreibe einen Kommentar