Java 在內(nèi)部類中訪問變量需要宣布為最終
如果您不想使其最終確定,則始終可以將其設(shè)為全局變量。
解決方法因此標(biāo)題說明了一切。我的內(nèi)出現(xiàn)編譯錯誤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 - 這條聯(lián)合sql語句哪里錯了2. mysql優(yōu)化 - 關(guān)于mysql分區(qū)3. 請教各位大佬,瀏覽器點(diǎn) 提交實(shí)例為什么沒有反應(yīng)4. java - Atom中文問題5. java - MySQL中,使用聚合函數(shù)+for update會鎖表嗎?6. css3 - 這個形狀使用CSS怎么寫出來?7. javascript - 為什么這個點(diǎn)擊事件需要點(diǎn)擊兩次才有效果8. node.js - 在vuejs-templates/webpack中dev-server.js里為什么要exports readyPromise?9. javascript - ionic2 input autofocus 電腦成功,iOS手機(jī)鍵盤不彈出10. java - C語言算法題-韓信點(diǎn)兵 求解?
