2015-07-09 69 views
3

您好我一直在我的脑子里呆了几个小时,在网上做了研究,但没有人似乎有答案。我的模拟器运行我的代码没有问题,然后再次运行它,我得到“Session'MainActivity':error”。我查看了这个主要活动约10次,但没有任何错误的迹象,它看起来应该工作得很好,我的意思是它工作之前没有问题。所以我不确定是否真的有问题,我没有看到Android Studio没有正确指出,或者这是一个不同的问题。Android Studio:Session'MainActivity':错误,但没有错误

任何帮助将不胜感激。谢谢。

package tekvision.codedecrypter; 
import android.content.Context; 
import android.content.Intent; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.Toast; 
import gameInfo.GameDatabase; 

public class MainActivity extends ActionBarActivity { 

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

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

    //Instantiate a GameDatabase object (this activity) 
    final GameDatabase gDB = new GameDatabase(context); 

    gDB.fillGameDatabase(); 

    //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) { 

      String ans = gDB.getAnswer("Ancient",1); 

      //Toast pop up message 
      Toast toast = Toast.makeText(getApplicationContext(), 
       ans , 
        Toast.LENGTH_SHORT); 

      toast.show(); 


      //Intent to go from main activity to campaign Level Select Activity 

      final Intent intent = new Intent(MainActivity.this, CampaignSelectLevel.class); 

      startActivity(intent); 

     } 
    }); 

} 

}

回答

0

尝试重建和清洁项目。 构建>重建项目 和 构建>清理项目

相关问题