java - Generate random sentence on button press, code looks right but isnt working -


I'm not sure what is wrong here, what I want to do is randomly delete an item from my array Which is like a random sentence, and then once it is generated, the button is pressed. All my codes are good for me but when I press the button it is causing an accident. Any ideas?

  package com.my.package; Import java.util.Random; Import android App Import android.content.Intent; Import android.content.res.Resources; Importroid.os.Bundle; Import android.view.View; Import android.widget.TextView; Import android.view.Menu; Import android.view.MenuInflater; Import android.view.MenuItem; Import android.view.View.OnClickListener; Public Class Randomization Increases Activity Equipments OnClickListener {Personal String [myString; Private Stable Last Random Rgenerator = New Random (); Private Text Viv TV; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); SetContentView (R.layout.main); Resource res = getResources (); MyString = res.getStringArray (R. O. Marrayre); String q = myString [rgenerator.nextInt (myString.length)]; TextView TV = (TextView) findViewById (R.id.text1); Tv.setText (Q); See nextButton = findViewById (R.id.next_button); NextButton.setOnClickListener (this); } @ Override Public Zero (see V) {Switch (v.getId ()} {Case RID.NX_button: TV.sextext (mystring.length)); break; }} @ Override Public Boolean On Crate Option Menu (menu menu) {super.onCreateOptionsMenu (menu); MenuInflater inflater = getMenuInflater (); Inflater.inflate (R. Menu.Menu 3, Menu); Back true; } @ Override Public Boolean On Option Itam (Menuitem Item) {Switch (ITAT). ITMID (Case) Raid Menu: Start Activity (New Intent (This, Main Class)); Back true; Case R.id.startnhie: startActivity (new intent (this, startnhie.class)); Back true; } return false; }}  

In your onCreate () , / P > TextView tv = (TextView) findViewById (R.id.text1);

to

  tv = (TextView) findViewById (R.id.text1);  

Because you have already declared the TextView TV as a frequency variable.


Comments