I ran this app on my phone just fine and then, after changing nothing, I changed out to install on my nexus 7. Now I am receiving this error.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.th3ramr0d.tc3studyguide.MainActivity.onCreate(MainActivity.java:37)
This is the code at line 37.
rateMe.setOnClickListener(new View.OnClickListener() {
This is the entire block of code for the setOnClickListener
Button rateMe = (Button)findViewById(R.id.rateMe);
rateMe.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.th3ramr0d.app"));
startActivity(intent);
}
});
XML File
<Button
android:id="@+id/rateMe"
android:text="Rate Me"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
This worked just fine on my phone. I then tried to install it on my phone and it gives me the exact same error now. I have tried:
Gradle Sync
Rebuild app
Clean app
Uninstalled app on phone and tablet
Restarted both devices
Restarted Android Studio
Restarted computer
OnCreate Method
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
boolean firstTimeRun = getFirstTimeRun();
if (firstTimeRun == true) {
firstTimeRun();
} else {
run();
}
Button rateMe = (Button)findViewById(R.id.rateMe);
ImageView prt = (ImageView)findViewById(R.id.prt);
ImageView pfp = (ImageView)findViewById(R.id.pfp);
rateMe.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.th3ramr0d.tc3studyguide"));
startActivity(intent);
}
});
prt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.th3ramr0d.prtmanagerfree"));
startActivity(intent);
}
});
pfp.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.th3ramr0d.poundforpoundfree"));
startActivity(intent);
}
});
}