应用随机崩溃,发生MainActivity会话错误

时间:2015-07-14 09:30:27

标签: java android android-studio

有时应用程序会运行,但它非常慢并且会混乱。我附上了主要活动和清单,我认为这是使应用程序陷入困境的原因之一。有时它会给我这个错误:会话' MainActivity':错误。

非常感谢任何帮助。

谢谢。

主要活动

import Graphics.MyGLSurfaceView;
import gameInfo.GameDatabase;

public class MainActivity extends ActionBarActivity {

    //Runs before the application is created
    private Button mCampaignButton;
    private Context context = this;
    private GLSurfaceView mGLView;

    //When the application is created
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //New thread to perform database creation / filling
        Runnable runnable = new Runnable(){
        public void run(){
            //Instantiate a GameDatabase object (this activity)
            final GameDatabase gDB = new GameDatabase(context);

            gDB.fillGameDatabase();
        }
    };

    Thread myThread = new Thread(runnable);
    myThread.start();

    mGLView = new MyGLSurfaceView(this);
    setContentView(mGLView);

    //Keeps screen on so it doesn't fall asleep
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //Finding button by button id after application is created
    mCampaignButton = (Button)findViewById(R.id.campaignButtonID);

    //Checks if the campaign button is clicked
    mCampaignButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Intent to go from main activity to campaign Level Select Activity
            final Intent intent = new Intent(MainActivity.this, CampaignSelectLevel.class);

            startActivity(intent);

        }
    });
    }

    }

Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tekvision.codedecrypter">
<!-- Tell the system this app requires OpenGL ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"  >

    <activity
        android:name=".MainActivity"
        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=".CampaignSelectLevel"
        android:label="@string/title_activity_campaign_select_level" >
    </activity>

    <!-- Anagrams.Modern Era is to get java class from different package-->
    <activity android:name="anagrams.Modern_Era"
              android:label="Modern_Era">

    </activity>

</application>

1 个答案:

答案 0 :(得分:1)

确保您声明应用程序所需的清单文件中的所有权限,即

    <uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>

有关详情,请查看:uses-permission