Java ADT错误代码

Java ADT错误代码,java,android,eclipse,adt,Java,Android,Eclipse,Adt,我正在ADT中创建一些应用程序,我正在遵循一个教程,但我在执行按钮时卡住了,无法将我的文本更改为其他内容。问题是,在本教程中,他使用的是旧版本的ADT,而我的版本较新,因此它不再工作。代码是这样的: (包裹名称等) 这可能是一个更好的例子。 我认为你的代码的主要错误是 final TextView textOne = (TextView) findViewById(R.id.textik); Button pushthis = (Button) findViewById(R.id.gombik

我正在ADT中创建一些应用程序,我正在遵循一个教程,但我在执行按钮时卡住了,无法将我的文本更改为其他内容。问题是,在本教程中,他使用的是旧版本的ADT,而我的版本较新,因此它不再工作。代码是这样的:

(包裹名称等)


这可能是一个更好的例子。

我认为你的代码的主要错误是

final TextView textOne = (TextView) findViewById(R.id.textik);
Button pushthis = (Button) findViewById(R.id.gombik);
它们不应该在这里被初始化和声明。如果您正在使用片段,则应将其移动到片段。下面是一个简单的例子

    public static class PlaceholderFragment extends Fragment implements Button.OnClickListener{
    TextView textOne;
    Button pushthis;
        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            textOne = (TextView) rootView.findViewById(R.id.textik);
            pushthis = (Button) rootView.findViewById(R.id.gombik);
            //set handlers and anything else
            pushthis.setOnClickListener(this);

            return rootView;
        }
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.gombik:
                   textOne.setText("HI");
                   break;
            }
        }
    }

应用程序并没有启动,但我只是需要一些帮助如何改变它。我需要添加一些动作,比如当我点击我的按钮时,它会改变文本。类似于:pushthis.setOnClickListener(newview.OnClickListener(){@Override public void onClick(视图arg0){//TODO自动生成的方法stub textOne.setText(“Hovno”);}}}}}}}如果您在Eclipse的控制台或错误选项卡中查看,它应该会告诉您为什么它不会启动。
    public static class PlaceholderFragment extends Fragment implements Button.OnClickListener{
    TextView textOne;
    Button pushthis;
        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            textOne = (TextView) rootView.findViewById(R.id.textik);
            pushthis = (Button) rootView.findViewById(R.id.gombik);
            //set handlers and anything else
            pushthis.setOnClickListener(this);

            return rootView;
        }
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.gombik:
                   textOne.setText("HI");
                   break;
            }
        }
    }