While trying to manipulate a TextView box, I kept recieving null pointer errors. I have discovered that my TextView box is not linked to my code despite the fact that I have set it to the correct ID. I do not know what the problem is though. I link all my TextViews the same way and this is first time that I have had this problem. This is the part of my XML file that defines the TextView's properties.
<TextView
android:id="@+id/textviewH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_alignTop="@+id/textView5"
android:layout_marginLeft="64dp"
android:text="@string/HumiumLink"
/>
This is my java file
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.activity_about_t2m, null);
Tv = ((TextView) findViewById(R.id.textviewH));
if (Tv != null)
{
Tv.setMovementMethod(LinkMovementMethod.getInstance());
}
dialog.setView(view);
dialog.setTitle("About T2M");
dialog.setIcon(R.drawable.ic_launcher);
dialog.setCancelable(false);
dialog.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
}
);
dialog.create();
dialog.show();
I have found that the code inside the if-statement never executes which means that Tv is null. Logcat even shows a strange error that I have not seen before. ![LogCat Error Messages][1] I circled it in blue. This is frustrating.
EDIT1:
This is all for a part of the menu called AboutT2M that is executed from the main activity. The following is the menu code from my main activity
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.AboutMorseID:
Intent AboutMorseI = new Intent(this, About_Morse.class);
startActivity(AboutMorseI);
break;
case R.id.SettingsID:
Intent SettingsI = new Intent(this, SettingsActivity.class);
startActivity(SettingsI);
break;
case R.id.ReadMeID:
Intent ReadMeI = new Intent(this, ReadMe.class);
startActivity(ReadMeI);
break;
case R.id.AboutT2MID:
Intent AboutT2MI = new Intent(this, About_T2M.class);
startActivity(AboutT2MI);
break;
default:
}
return true;
}
[1]: https://i.stack.imgur.com/vRH7Q.pngemphasized text