Duplicate id @+id/textView1, already defined earlier in this layout Android Error


This is a Lint error message, which means that you have assigned the same @+id to two or more elements (Views) in your layout.xml file.

The id that you assign to the Views (TextViews, EditText, ImageViews, Buttons or layouts like LinearLayouts, GridLayout, TableLayout, TableRow, etc) must be unique or else when you would try to access them by its ID in your java code ( eg. findViewById(R.id.textView1) you may get an exception.

Solution

Just double click on the error message under Lint Warning and it will take you to the place where you have a conflict of Duplicate id. Rename it to something unique and the issue will be resolved.

Note: If you wish to have certain Views to have the same ID then you may have to suppress this Lint Error message, you can achieve this by going to Preferences -> Android -> Lint Error Checking and search DuplicateIds, change its severity from Fatal to Warning. Clean + Build your project and you may no more get the duplicate id error.




Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.