Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid app stops unexpectdly
    text
    copied!<p>I am trying to start another activity when a menu item is selected. However the app just stops unexpectedly when I run the application on my phone and press any of the menu items.</p> <p>Here is an the NewPlanet activity I am trying to start for example:</p> <pre><code>package com.example.hello_world; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.ImageView; public class NewPlanet extends Activity { @Override //onCreate method to start the app in system memory protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); //area to view the application content setContentView(R.layout.activity_add); //reference imageView UI element ImageView marsImage = (ImageView) findViewById(R.id.imageMars); //attach mars image to an event //onClick listener interface needs to be implemented marsImage.setOnClickListener(new View.OnClickListener() { @Override //onClick method for mars image being implemented public void onClick(View v) { //create new WorldGen instance WorldGen mars = new WorldGen("Mars", 642, 3.7); //add a colony to the mars object mars.setPlanetColonies(1); //destroy the object after use finish(); } }); } //keyDown event handler @Override public boolean onKeyDown(int keyCode, KeyEvent event) { //check that if the x key has pressed down //any event handler can still operate on this event if (keyCode == KeyEvent.KEYCODE_X) { //return control from the function finish(); return true; } return false; } } </code></pre> <p>Here is the activity that contains menu event handler (onOptionsItemSelected) method I am starting the NewPlanet activity from:</p> <pre><code>package com.example.hello_world; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class MainActivity extends Activity { //new worldgen object WorldGen earth = new WorldGen("Earth", 5973, 9.78); @Override //parameter contains all the saved states and settings of the UI. protected void onCreate(Bundle savedInstanceState) { //passes in the UI states to the onCreate initialzing method. super.onCreate(savedInstanceState); ////loads the XML layout definition via this method (specifies the directory). setContentView(R.layout.activity_main); //create new world object WorldGen earth = new WorldGen("Earth", 5973, 9.78); //add one colony to earth object earth.setPlanetColonies(1); //add a military base earth.setPlanetMilitary(1); //add 1000 immigrants to population earth.setColonyImmigration(1000); //add 100 soldiers earth.setBaseProtection(100); //turn the boolean force field on earth.turnForceFieldOn(); } //set up world start values protected void setStartWorldValues() { } //set up the start screen text private void setUpScreenText() { //textview object holding the actual values. //each textview object displays a different dataView //planet name textView. TextView planetNameValue = (TextView) findViewById (R.id.dataView1); planetNameValue.setText(earth.planetName); //planet mass textViewaq TextView planetMassValue = (TextView) findViewById (R.id.dataView2); planetMassValue.setText(earth.planetMass); //planet gravity textView TextView planetGravityValue = (TextView) findViewById (R.id.dataView3); planetGravityValue.setText(String.valueOf(earth.planetGravity)); //planet colonies textView TextView viewplanetColoniesValue = (TextView) findViewById (R.id.dataView4); viewplanetColoniesValue.setText(String.valueOf(earth.planetColonies)); //planet population textView TextView planetPopValue = (TextView) findViewById (R.id.dataView5); planetPopValue.setText(String.valueOf(earth.planetPopulation)); //planet military textView TextView planetMilitaryValue = (TextView) findViewById (R.id.dataView6); planetMilitaryValue.setText(String.valueOf(earth.planetMilitary)); //planet bases textView TextView planetBasesValue = (TextView) findViewById (R.id.dataView7); planetBasesValue.setText(String.valueOf(earth.planetBases)); //planet forcefield state textView TextView planetFieldValue = (TextView) findViewById (R.id.dataView8); planetFieldValue.setText(String.valueOf(earth.getForceFieldState())); } @Override //inflates the menu with user defined xml menu file using the CreateOptionsMenu method // public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); //return value for a properly implemented menu resource return true; } @Override //decide what menu item has been selected public boolean onOptionsItemSelected(MenuItem item) { //switch statement to determine which menu item was selected by ID switch (item.getItemId()) { //menu add selected case R.id.menu_add: //explicit intent instance //call startActivity static method and start the class Intent intent_add = new Intent(this, NewPlanet.class); this.startActivity(intent_add); break; //config method selected case R.id.menu_config: //call startActivity static method and start the class Intent intent_config = new Intent(this, ConfigPlanet.class); this.startActivity(intent_config); break; case R.id.menu_travel: //call startActivity static method and start the class Intent intent_travel = new Intent(this, TravelPlanet.class); this.startActivity(intent_travel); break; case R.id.menu_attack: //call startActivity static method and start the class Intent intent_attack = new Intent(this, AttackPlanet.class); this.startActivity(intent_attack); break; default: //return control back to the superclass - like a return false return super.onOptionsItemSelected(item); } //return true for success return true; } } </code></pre> <p>Here is my error log file (errors/warnings from a run just now):</p> <pre><code>eclipse.buildId=v22.3.0-887826 java.version=1.7.0_45 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB Framework arguments: -product com.android.ide.eclipse.adt.package.product Command-line arguments: -os win32 -ws win32 -arch x86_64 -product com.android.ide.eclipse.adt.package.product Warning Sat Dec 07 15:37:17 GMT 2013 Warning: The environment variable HOME is not set. The following directory will be used to store the Git user global configuration and to define the default location to store repositories: 'C:\Users\namso1902'. If this is not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and EGit might behave differently since they see different configuration options. This warning can be switched off on the Team &gt; Git &gt; Confirmations and Warnings preference page. eclipse.buildId=v22.3.0-887826 java.version=1.7.0_45 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB Framework arguments: -product com.android.ide.eclipse.adt.package.product Command-line arguments: -os win32 -ws win32 -arch x86_64 -product com.android.ide.eclipse.adt.package.product Warning Sat Dec 07 15:37:17 GMT 2013 Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory. The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in this system level configuration. The Git installation location can be configured on the Team &gt; Git &gt; Configuration preference page's 'System Settings' tab. This warning can be switched off on the Team &gt; Git &gt; Confirmations and Warnings preference page. </code></pre> <p>Here is the xml manifest:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hello_world" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.hello_world.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.example.hello_world.NewPlanet"/&gt; &lt;activity android:name="com.example.hello_world.ConfigPlanet"/&gt; &lt;activity android:name="com.example.hello_world.TravelPlanet"/&gt; &lt;activity android:name="com.example.hello_world.AttackPlanet"/&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Cannot get the stack trace sorry.</p> <p>Thanks in advance</p>
 

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