Simple Activity Related

by raqz » Wed, 31 Mar 2010 01:16:18 GMT

Sponsored Links
 I have this main class which displays a button and on click of the
button, the NextActivity class should be called. I have defined the
NextActivity class in the same package. But when I click the button,
the application closes stating there is some error.

But when i directly start an intent (un comment the last line). The
application goes there without displaying the Main class. Please let
me know what is the mistake i am doing.

package com.intents;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainClass extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        Button btnOpen = (Button) findViewById(;
        btnOpen.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                        "You have clicked the Open button",
                Intent i = new Intent();
                i.setClassName("com.intents", "NextActivity");


       //startActivity(new Intent( this, NextActivity.class));


Simple Activity Related

by Mark Murphy » Wed, 31 Mar 2010 01:28:35 GMT


Use adb logcat, DDMS, or the DDMS perspective in Eclipse to find the
Java stack trace for your error.

In this case, it will be something about your Intent being malformed:

The above Intent is different than the one you said works:

Your first Intent does not have any sort of Context (e.g., your
Activity) associated with it, and so it will result in some exception
when you try to use it.

Instead, use the form of your second Intent, though you will need to
make it be MainClass.this instead of just "this" for it to compile.

Mark Murphy (a Commons Guy)  | 

Android App Developer Books: 


Sponsored Links

Other Threads

1. YouTube app Intent and Extras

Hi all,

I am trying to find out the intents and extras used by the YouTube

In it's most basic form the intent to view a video.



2. Create custom mime type handler


I need to create a handler for the files with custom MIME type, e.g.

Could anybody please provide me with the detailed tutorial how to
archive it?
As far as i understand, i need to create a custom content provider to
take care about my type object storage, so i can handle the queries to
get some data about files, e.g. it's path. But i don't know how to
make the system to call my Activity to react on VIEW action for
specific type.

Thanks in advance.


3. Slow to load emulator with eclipse

4. Sync data in Android to/from a relational database with db4o

5. facing problem with bitmap size.

6. running code immediately after activity is displayed

7. about viewstub