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.app.Activity;
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. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnOpen = (Button) findViewById(R.id.btnNext);
        btnOpen.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getBaseContext(),
                        "You have clicked the Open button",
                        Toast.LENGTH_SHORT).show();
                Intent i = new Intent();
                i.setClassName("com.intents", "NextActivity");
                startActivity(i);

            }

        });
       //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)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books 

--


Sponsored Links


Other Threads

1. How to cancel a notification?

I am writing a content provider and would notify some events on the
status bar. I want to remove the notification after a period of time
without user's notice.
Any idea?
Besides, should I always have to set a PendingIntent for the
notification? Could I use a null intent without doing anything but
leave?

Thanks.
--~--~---------~--~----~------------~-------~--~----~

2. How to get uncompressed sound(uncompressed MP3) data in Android framework

Is there any way to get uncompressed sound (uncompressed MP3) data in
Android framework?
And how do we pass this uncompressed data buffer to audio flinger for
audio playback?
--~--~---------~--~----~------------~-------~--~----~

3. How to: Set up developer phone with no data plan or sim card

4. How to merge aac recognizer to Cupcake

5. Developer phone with sim card but no service

6. Booting issue

7. Dev phone w/ at&t sim card but no actual service