变量是内部类中访问。需要声明的最终

编程入门 行业动态 更新时间:2024-10-27 04:32:08
本文介绍了变量是内部类中访问。需要声明的最终的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此​​,标题说明了一切。 我得到我的onClick

的内部编译错误

我敢肯定,这是一个非常简单的解决,但我不完全知道如何把它写。我仍然在android开发的早期阶段,所以请原谅我的小白的烦躁。 :)

这里的code。

公共类fieldsActivity延伸活动{ 按钮addSiteButton; 按钮cancelButton; 按钮signInButton; / **  *第一次创建活动时调用。  * / @覆盖 公共无效的onCreate(包savedInstanceState){     super.onCreate(savedInstanceState);     //创建为活动窗口自定义标题栏     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);     的setContentView(R.layout.fields);     //使用自定义布局标题栏     。getWindow()setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.topbar);     寻呼机适配器=新寻呼机();     ViewPager mPager =(ViewPager)findViewById(R.id.fieldspager);     mPager.setAdapter(适配器);     mPager.setCurrentItem(1);     addSiteButton =(按钮)findViewById(R.id.addSiteButton);     addSiteButton.setOnClickListener(新View.OnClickListener(){         @覆盖         公共无效的onClick(视图v){            mPager.setCurrentItem(2,真); //编译错误发生在这里。         }     });     cancelButton =(按钮)findViewById(R.id.cancel_button);     signInButton =(按钮)findViewById(R.id.sign_in_button); }

解决方案

该错误说明了一切,改变:

ViewPager mPager =(ViewPager)findViewById(R.id.fieldspager);

最后ViewPager mPager =(ViewPager)findViewById(R.id.fieldspager);

So the title says it all. I'm getting a compilation error inside of my onClick

I'm sure this is a really simple fix, but I'm not exactly sure how to write it. I'm still in the early stages of android development, so pardon my noob-ness. :)

Here's the code.

public class fieldsActivity extends Activity { Button addSiteButton; Button cancelButton; Button signInButton; /** * Called when the activity is first created. */ @Override public 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() { @Override public 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); }

解决方案

The error says it all, change:

ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager);

to

final ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager);

更多推荐

变量是内部类中访问。需要声明的最终

本文发布于:2023-11-23 17:35:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622309.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   类中   声明

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!