为了账号安全,请及时绑定邮箱和手机立即绑定

引入全局变量报错

package com.example.htc;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class frist extends Activity {
private Button BT1;
private Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.factivity);
		BT1 = (Button) findViewById(R.id.button1);
		BT1.setOnClickListener(new OnClickListener() {
			mContext = this;
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent IN = new Intent(frist.this, second.class);
				frist.this.startActivity(IN);
			}
		});
	}
}

mContext = this; 报错 为什么?

Description Resource Path Location Type

Syntax error on token "qqq", VariableDeclaratorId expected after this token frist.java /HTC/src/com/example/htc line 22 Java Problem


正在回答

1 回答

mContext = this 这个要放到外面 不能放在匿名类里面 这样是取不到this的

而且你Intent内里面直接用了first.this了  就没必要 再 搞一个mContext了  

0 回复 有任何疑惑可以回复我~
#1

芒种啊 提问者

非常感谢!
2016-01-05 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android攻城狮的第一门课(入门篇)
  • 参与学习       312506    人
  • 解答问题       4931    个

想快速掌握Android应用开发基础,选择学习这门课程就对了。

进入课程

引入全局变量报错

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号