Note that there are some explanatory texts on larger screens.

plurals
  1. PONew intent, how to link to my class?
    primarykey
    data
    text
    <p>I'm beginner in Android (and java), and I'm just playing around and want to create new View after clicking a button. Here is my code so far:</p> <p><strong>Main class</strong></p> <pre><code>package myTests.homeSpace; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class TestsActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener( new OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(TestsActivity.this, screen1.class); startActivity(myIntent); } }); } } </code></pre> <p><strong>Class to run after clicking button</strong></p> <pre><code>package myTests.homeSpace; import android.app.Activity; import android.os.Bundle; public class screen1 extends Activity { @Override public void onCreate(Bundle SavedBundleInstance) { super.onCreate(SavedBundleInstance); setContentView(R.layout.screen1); } } </code></pre> <p>The problem is, after hitting button I got "Unforunately, Tests has stopped" error. ("Tests" is application name). I know (or guess) the problem is in this line <code>Intent myIntent = new Intent(TestsActivity.this, screen1.class);</code> I guess my reference to class <code>screen1</code> is wrong somehow, but I have no idea why. There are no compilation errors nor warnings, layout .xmls shouldn't be wrong.</p> <p>Could any of you please advice me any solution?</p> <p><strong>EDIT</strong></p> <p><strong>MANIFEST</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="myTests.homeSpace" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="15" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".TestsActivity" 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;/application&gt; &lt;/manifest&gt; </code></pre> <p><strong>CONSOLE OUTPUT</strong></p> <pre><code>[2012-06-20 19:56:21 - ddms] null java.lang.NullPointerException at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213) at com.android.ddmlib.Client.sendAndConsume(Client.java:575) at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142) at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) at com.android.ddmlib.Client.getJdwpPacket(Client.java:672) at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) </code></pre>
    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