That's not the problem, he's reporting a compiler error. (He may yet
have that problem downstream of this one).
Darshan, what you've written is not valid Java syntax.
You mean one of these two constructors
ComponentName(<string>, <string>)
or
ComponentName(<context>, <class>).
What you've supplied as arguments are identifiers which aren't
defined.
A string is in double quotes. A class is referenced by the name of the
class followed by .class
And the context would be the activity. In this case, you'd write
intentsTest.this since your code is inside a nested class, but usually
you'd just write 'this' (no quotes).
So you either meant:
new CompnentName("com.darshan.demos", "com.darshan.demos.IntentsNew")
or
new ComponentName(intentsTest.class,
com.darshan.demos.IntentsNew.class)
I'd generally prefer the second -- that way the compiler can detect
any incorrect class name, and you can't get the package name wrong.
Also, I'll note in passing that your class name, "intentTest", doesn't
conform to convention. Normally, class names begin with a capital
letter. This convention is widespread and strong enough to be worth
paying attention to. Even if nobody else reads your code -- following
it will help you read other people's code and APIs. It is actually
quite rare to find Java code that doesn't follow this.
On Apr 2, 6:40 pm, Jason LeBlanc <[email protected]> wrote:
> Did you register the activity in the manifest?
> J
>
> On Apr 2, 2010 1:29 PM, "Darshan Hegde" <[email protected]> wrote:
>
> Hello,
>
> I am a new bee to Android. I have Eclipse + ADT development
> environment. I am trying to start a new activity by clicking on a
> button on the existing activity. But package is not being resolved
> some how,
>
> here is my code...
>
> package com.darshan.demos;
>
> import android.app.Activity;
> import android.content.ComponentName;
> import android.content.Intent;
> import android.os.Bundle;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
>
> public class intentsTest extends Activity {
> /** Called when the activity is first created. */
> �...@override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> Button button = (Button) findViewById(R.id.button);
> button.setOnClickListener(myNewActivity);
> }
>
> private OnClickListener myNewActivity = new OnClickListener() {
> public void onClick(View v) {
> Intent intent = new Intent();
> ComponentName comp = new
> ComponentName(com.darshan.demos,com.darshan.demos.IntentsNew);
> intent.setComponent(comp);
> startActivity(intent);
>
> }
> };
>
> }
>
> IntentsNew is the new activity that I want to start.
>
> The error is...
>
> Description
> Resource Path Location Type
> com.darshan.demos cannot be resolved to a type intentsTest.java
> iIntents/src/com/darshan/demos line 25 Java Problem
> com.darshan.demos.IntentsNew cannot be resolved
> intentsTest.java iIntents/src/com/darshan/demos line 25 Java Problem
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%2Bunsubs
> [email protected]>
> For more options, visit this group
> athttp://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe, reply using "remove me" as the subject.