Note that there are some explanatory texts on larger screens.

plurals
  1. POPlease help with this error when using separate class file in Android app
    primarykey
    data
    text
    <p>I'm having trouble trying to figure out how to use a function contained in a separate class file.</p> <p>My separate class file is called EncounterGenerator.java. And I call it like this:</p> <p><code>EncounterGenerator Encounter;</code> <code>testString = Encounter.EncounterGeneratorText();</code></p> <p>So below is my main file called HelloAndroid.java:</p> <pre><code>package mot.HelloAndroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.widget.Button; import android.view.View; import android.view.View.OnClickListener; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ TextView tvIntro; TextView tvNavigator; TextView tvAction; EncounterGenerator Encounter ; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); //setup text views this.setContentView(R.layout.main); tvIntro = (TextView)findViewById(R.id.tvIntro); tvNavigator = (TextView)findViewById(R.id.tvNavigator); tvAction = (TextView)findViewById(R.id.tvAction); //display game intro tvIntro.setText("Text Adventure"); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } tvIntro.setText("This is a really cool text adventure game!"); //define navigation buttons Button btnNorth = (Button)findViewById(R.id.btnNorth); btnNorth.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tvIntro.setText("You go north"); String testString = "nothing"; try { testString = Encounter.EncounterGeneratorText(); } catch (Exception e) { e.printStackTrace(); } testString = Encounter.EncounterGeneratorText(); tvIntro.setText(testString); } }); } } </code></pre> <p></p> <p>and this is my separate class file called EncounterGenerator.java:</p> <pre><code>package mot.HelloAndroid; public class EncounterGenerator { public String EncounterGeneratorText() { String encounterText = "test value"; return encounterText; } } </code></pre> <p>Everytime I run it, and then click the button that calls the function EncounterGeneratorText() I get this error in my AVP:</p> <p>The application Hello Android has stopped unexpectedly...please try again</p> <p>If anyone could help, I'd greatly appreciate it!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload