Reputation:
I am experiencing an error which I'm pretty sure has nothing to do with my code. I'm using Android Studio.
This error came about when I renamed a separate activity XML file and it prompted me if I wanted it to auto update the file with the new name which I allowed. I then saw an error on my MainActivity.java. After inspection I saw that the error came from the R
in setContentView(R.layout.activity_main);
.
package nz.school.app.nb;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Inits the activity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Home");
}
// Timetable button listener
public void timeTableButtonListener(View view){
Intent kamarActivity = new Intent(this, TimetableActivity.class);
startActivity(kamarActivity);
}
// Contacts button listener
public void contactsButtonListener(View view){
Intent contactsActivity = new Intent(this, ContactActivity.class);
startActivity(contactsActivity);
}
// Links button listener
public void linksButtonListener(View view){
Intent linksActivity = new Intent(this, LinksActivity.class);
startActivity(linksActivity);
}
// Notices button listener
public void noticesButtonListener(View view){
Intent newsActivity = new Intent(this, NoticesActivity.class);
startActivity(newsActivity);
}
// Events button listener
public void eventsButtonListener(View view){
Intent eventActivity = new Intent(this, EventsActivity.class);
startActivity(eventActivity);
}
}
I then had a quick look online with nothing that would help. I decide to revert to my previous version with no errors but the same thing happens. I then remove the whole app folder and replace with my friend (We are both developing app) as he has the older version on his machine. After that the problem seemed to disappear which made me very happy. The next day I open the MainActivty.java
and as soon as the file was opened the error came back.
I am now very confused to what this issue is from.
Upvotes: 1
Views: 1468
Reputation: 353
Clean your project (Build>Clean) and make sure all sdk packages installed correctly.
Upvotes: 1
Reputation: 2188
try to import nz.school.app.R
not import nz.school.app.nb.R;
after that try Clean Project and then Rebuild Project from Build menu and click sync project with gradle file icon and but if you face still same problem then look at very carefully to you xml
file if you found any error there then fix it and try same process.
Upvotes: 1
Reputation:
And a custom class with your project namespace:
import nz.school.app.nb.R;
Upvotes: 1