Java 在內(nèi)部類中訪問(wèn)變量。需要宣布為最終
如果您不想使其最終確定,則始終可以將其設(shè)為全局變量。
解決方法因此標(biāo)題說(shuō)明了一切。我的內(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. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.2. 為什么我ping不通我的docker容器呢???3. android - webview 自定義加載進(jìn)度條4. mysql - 怎么讓 SELECT 1+null 等于 15. javascript - 微信音樂(lè)分享6. 網(wǎng)頁(yè)爬蟲(chóng) - 用Python3的requests庫(kù)模擬登陸B(tài)ilibili總是提示驗(yàn)證碼錯(cuò)誤怎么辦?7. javascript - 微信小程序封裝定位問(wèn)題(封裝異步并可能多次請(qǐng)求)8. 并發(fā)模型 - python將進(jìn)程池放在裝飾器里為什么不生效也沒(méi)報(bào)錯(cuò)9. linux - openSUSE 上,如何使用 QQ?10. python 怎樣用pickle保存類的實(shí)例?
