Java 在內(nèi)部類中訪問變量。需要宣布為最終
如果您不想使其最終確定,則始終可以將其設(shè)為全局變量。
解決方法因此標(biāo)題說明了一切。我的內(nèi)出現(xiàn)編譯錯(cuò)誤onClick。
這是代碼。
public class fieldsActivity extends Activity {Button addSiteButton;Button cancelButton;Button signInButton;/** * Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // to create a custom title bar for activity window requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.fields); // use custom layout title bar getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbar); Pager adapter = new Pager(); ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager); mPager.setAdapter(adapter); mPager.setCurrentItem(1); addSiteButton = (Button) findViewById(R.id.addSiteButton); addSiteButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) { mPager.setCurrentItem(2,true); //Compilation error happens here.} }); cancelButton = (Button) findViewById(R.id.cancel_button); signInButton = (Button) findViewById(R.id.sign_in_button);}
相關(guān)文章:
1. mysql - 把一個(gè)表中的數(shù)據(jù)count更新到另一個(gè)表里?2. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)3. node.js - 為什么微信的消息MsgId出現(xiàn)重復(fù)了,無法排重了。。4. mysql的主從復(fù)制、讀寫分離,關(guān)于從的問題5. MySQL 截短某一列的字符串6. 請(qǐng)教使用PDO連接MSSQL數(shù)據(jù)庫插入是亂碼問題?7. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會(huì)帶來哪些效率或者其他方面的好處8. mysql - 字符串根據(jù)字典替換9. 視頻文件不能播放,怎么辦?10. node.js - nodejs開發(fā)中常用的連接mysql的庫
