Ошибки компилятора после создания кнопки
Я пытался добавить кнопку в приложение для 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 ответ
Попробуйте использовать или удалить com.user.app.
из TextView Id и String
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;