按下按钮后出现编译器错误

时间:2018-10-06 10:09:27

标签: java android compiler-errors javacompiler

我尝试向Android应用添加按钮。它以前是编译的,以前没有问题。我不确定是否误编辑了某些内容?

@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
            View rootView = inflater.inflate(com.user.app.R.layout.fragment_gallery, container, false);
            TextView textView = (TextView) rootView.findViewById(com.user.app.R.id.section_label);
            textView.setText(getString(com.user.app.R.string.section_format,getArguments().getInt(ARG_SECTION_NUMBER)));
            return rootView;
        }
    }

这将返回错误:

> /home/user/AndroidStudioProjects/AndroidApp/app/src/main/java/com/user/app/Gallery.java:127:
> error: cannot find symbol
>             textView.setText(getString(com.user.app.R.string.section_format,getArguments().getInt(ARG_SECTION_NUMBER)));
>                                                                          ^   symbol:   variable section_format   location: class string 1 error
> :app:compileDebugJavaWithJavac FAILED
> 
> FAILURE: Build failed with an exception.
> 
> * What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
> > Compilation failed; see the compiler error output for details.

“ section_format”为红色。如果我没记错的话,它正在寻找它,但找不到它?当我转到文件R.java时,可以在其中找到它?所以它应该能够找到它?

错误不会产生任何结果,并且似乎是由于尽管存在“ section_format”也无法找到它。

1 个答案:

答案 0 :(得分:0)

尝试使用或从TextView ID和字符串中删除com.user.app.

TextView textView = (TextView) rootView.findViewById(R.id.section_label);

和来自

getString(com.user.app.R.string.section_format,getArguments().getInt(ARG_SECTION_NUMBER))

确保您的导入是

import android.widget.TextView;