Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.NullPointerException at android.content.ContextWrapper.getPackageName ANDROID
    primarykey
    data
    text
    <p>Hey I want to start an Activity from my MainActivity but not in the oncreate method.</p> <pre><code>public void awe() { Intent myIntent = new Intent(MainActivity.this, Awesome.class); MainActivity.this.startActivity(myIntent); } </code></pre> <p>Another class calls the method awe() and what I get is a crash and</p> <pre><code>05-25 04:06:51.034: E/AndroidRuntime(7161): FATAL EXCEPTION: main 05-25 04:06:51.034: E/AndroidRuntime(7161): java.lang.NullPointerException 05-25 04:06:51.034: E/AndroidRuntime(7161): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:151) 05-25 04:06:51.034: E/AndroidRuntime(7161): at android.content.ComponentName.&lt;init&gt;(ComponentName.java:106) 05-25 04:06:51.034: E/AndroidRuntime(7161): at android.content.Intent.&lt;init&gt;(Intent.java:2895) 05-25 04:06:51.034: E/AndroidRuntime(7161): at package name.MainActivity.awe(MainActivity.java:215) </code></pre> <p>Someone knows what I can do?</p> <p>MainActivity</p> <pre><code>public class MainActivity extends Activity implements OnClickListener { // (variable stuff) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonE = (Button) findViewById(R.id.buttonEASY); buttonM = (Button) findViewById(R.id.buttonMED); // here I do all that button stuff for the layout } public void onClick(View arg0) { System.out.println("click"); if (arg0==buttonE) { int checkedRadioButton = radioGroup1.getCheckedRadioButtonId(); String radioButtonSelected = ""; switch (checkedRadioButton) { case R.id.radio0 : radioButtonSelected = "radiobutton1"; Toast.makeText(getApplicationContext(), "Easy, 10 selected", Toast.LENGTH_SHORT).show(); setContentView(R.layout.raten); // Button stuff, again. } public void awe() { Intent tutorial = new Intent(MainActivity.this, Awesome.class); if (tutorial != null) { startActivity(tutorial); } } </code></pre> <p>Easy.java</p> <p>Nothing important here, the place where I refer to awe():</p> <pre><code>if (s==max+1){System.out.println("AWESOME!"); MainActivity mA = new MainActivity(); mA.awe();} </code></pre> <p>Awesome.java</p> <pre><code>public class Awesome extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.awesome); } </code></pre> <p>I hope I now posted everything that is important</p>
    singulars
    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