Hey guys. I'm working on an Android Application and I'm using the .setAdapter command and I'm getting the red squiggle under it. Eclipse tells me this. "The method setAdapter(PagerAdapter) in the type ViewPager is not applicable for the arguments (Upperbody.MyPagerAdapter)"

Specifically right here;

Code:

myPager.setAdapter(adapter);


Here's my code;

Code:

package com.example.gymbuddy;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

public class Upperbody extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_upperbody);
      
       MyPagerAdapter adapter = new MyPagerAdapter();
       ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
       myPager.setAdapter(adapter);
       myPager.setCurrentItem(2); }
   
   public class MyPagerAdapter extends Activity {
      
        public int getCount() {
            return 9;
        }
 
        public Object instantiateItem(View collection, int position) {
 
            LayoutInflater inflater = (LayoutInflater) collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
            int resId = 0;
            switch (position) {
            case 0:
                resId = R.layout.upper0;
                break;
            case 1:
                resId = R.layout.upper1;
                break;
            case 2:
                resId = R.layout.upper2;
                break;
            case 3:
                resId = R.layout.upper3;
                break;
            case 4:
                resId = R.layout.upper4;
                break;
            case 5:
               resId = R.layout.upper5;
               break;
            case 6:
               resId = R.layout.upper6;
               break;
            case 7:
               resId = R.layout.upper7;
               break;
            case 8:
               resId = R.layout.upper8;
               break; }
 
            View view = inflater.inflate(resId, null);
 
            ((ViewPager) collection).addView(view, 0);
 
            return view; }
       
        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager) arg0).removeView((View) arg2); }
       
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == ((View) arg1); }
       
        public Parcelable saveState() {
            return null; }
       
   }
   
}
Well, ViewPager.setAdapter() expects a variable of type PagerAdapter as an argument, but you're passing MyPagerAdapter, which extends Activity. I'm not familiar with Android coding specifically, but does MyPagerAdapter need to either extend PagerAdapter or implement the PagerAdapter interface?
Kerm; You are surely a genius Smile
For future reference, which one was it?
I should have had MyPagerAdapter extend PagerAdapter, instead of it extending Activity.

SUPER RE-EDIT!

All of my issues are solved. Planning to have the lite version of my app done in a few weeks. Thank you so much guys! Smile
joshie75 wrote:
I should have had MyPagerAdapter extend PagerAdapter, instead of it extending Activity.

SUPER RE-EDIT!

All of my issues are solved. Planning to have the lite version of my app done in a few weeks. Thank you so much guys! Smile
Great, glad to hear we helped you resolve your issues! Might I ask what you're making, actually? Also, I've been starting to seriously toy with the idea of porting some of my calculator projects to Android apps; is Java (is this Java or C#?) the only choice? Any particular lessons or experiences you'd like to mention from your own app-making work?
You can either use java or C(++) for apps (officially supported by google afaik). If you do C(++), you still need a java program. Why? Android is dumb.

Web apps are also probably possible somehow (for HTML/javascript based apps)
AHelper wrote:
You can either use java or C(++) for apps (officially supported by google afaik). If you do C(++), you still need a java program. Why? Android is dumb.

Web apps are also probably possible somehow (for HTML/javascript based apps)
Fascinating. Part of my motivation comes from wanting to actually see a little bit of profit off of some of my programming, although I acknowledge that it would probably be a small pittance. Smile
AHelper wrote:
You can either use java or C(++) for apps (officially supported by google afaik). If you do C(++), you still need a java program. Why? Android is dumb.

Web apps are also probably possible somehow (for HTML/javascript based apps)


This is even futher offtopic, but JNI and the NDK (native development kit) are a real pain in the arse to work with -- it took me a long time to even figure out how to debug code on-device, and most emulators won't support native execution.
I'm actually working on an app right now that will basically walk you through a workout that focuses on specific muscle groups.
There is going to be a lite version with 50-75% of the features which should be done next weekend. Then I will be doing a full version with the rest of the features for a very small fee, it will probably only cost $0.49
@Kerm, Android is mainly based off of Java, and is easiest to program the applications through Java. I have heard of people using other languages, but I'm not sure how / what languages. As for my experience I still consider myself a noobie to the world of Android programming. I can tell you one thing; at first Android programming may seem very different from any other language you've done, but keep working at it, as it becomes simple and easy to work with.
AHelper wrote:
If you do C(++), you still need a java program.


Nope. As of Gingerbread you can do entirely native apps.

Quote:
Why? Android is dumb.


No, because C/C++ is not a great dev environment, and most importantly because Dalvik byte code is portable. Something that really matters since Android runs on ARMv6, ARMv7 (with and without NEON), x86, and MIPS.

If you want to use a scripting language there is also SL4A: http://code.google.com/p/android-scripting/
1) Ah, Google kept saying that you needed a Java program to start C(++) programs. That is news.

2) My comment was only directed at the fact that you required java, so said Google (from the page that ICS dev sent me to). Also, C(++) is required for speed-intense code, such as physics engines (looks at Bullet) and for interfacing with the hardware (which I want to muck with). I of course know about multiple CPUs. I only care about my device Smile
AHelper wrote:
1) Ah, Google kept saying that you needed a Java program to start C(++) programs. That is news.


http://android-developers.blogspot.com/2011/01/gingerbread-ndk-awesomeness.html

Quote:
2) My comment was only directed at the fact that you required java, so said Google (from the page that ICS dev sent me to). Also, C(++) is required for speed-intense code, such as physics engines (looks at Bullet) and for interfacing with the hardware (which I want to muck with). I of course know about multiple CPUs. I only care about my device Smile


False on the speed-intensive code part - your algorithm and data structure choices are *far* more important than doing it in C/C++. Java is plenty capable of doing physics (look at Minecraft - or Angry Birds). Heck, most games these days are using things like Unity, which uses C#

As for interfacing with hardware - depends on what hardware you are referring to, but on Android no. Java can interface with the hardware, and C/C++ can not. Hardware interfacing always happens through an API anyway - the language is irrelevant (I mean that on desktop, too. The days of directly accessing hardware via assembly are *looooong* over)
<offtopic>
Ah, I must have just started trying too long ago. I think I started out before it was pure native code, and I kept my links after that change.

About the speed intensive: "Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on." -- Google

My post looked at Bullet, a C++ open source physics engine. I am not going to port it, it already works just fine on android.

Minecraft and Angry Birds are created using the NDK. (jens bergensten; ARM)

"The days of directly accessing hardware via assembly are *looooong* over" I never said I would access the hardware using assembly language. I guess I wasn't clear: I need to gain access more direct to the hardware than with Java. For example, mucking with the boot partition and hardware that Android doesn't use correctly.

</offtopic>

Any progress on said Android app?
Yes progress is being made!
As of right now, I am doing some core coding on my benchmark page. This will let you input a few numbers such as weight, how many pushups, situps, and pullups you can do, and it will then do some calculations to help you start off with the right amount of weights.
AHelper wrote:
I guess I wasn't clear: I need to gain access more direct to the hardware than with Java. For example, mucking with the boot partition and hardware that Android doesn't use correctly.


I guess I wasn't clear. You can't do *any* of that with C++ on Android. On Android, Java can use most of the hardware, C++ can use almost none of it. On all modern systems the amount you can interact with hardware is determined entirely by the APIs given to you, not the language.

And what do you mean by "hardware that Android doesn't use correctly"?
Getting another small error; Application is crashing due to something with one of my simple fade in animations on my splash screen.

My application splash screen is set to have one image fade in, then another, and then after the second one finishes, it's set to start my Main activity.

As soon as my second image is almost done fading in, it crashes.

Here is my SplashScreen activity;

Code:

package com.example.gymbuddy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashScreen extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_splashscreen);
      
       ImageView gym = (ImageView) findViewById(R.id.imageView1);
       Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.gym);
       gym.startAnimation(fade1);
      
       ImageView buddy = (ImageView) findViewById(R.id.imageView2);
       Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.buddy);
       buddy.startAnimation(fade2);
          fade2.setAnimationListener(new AnimationListener() {

            public void onAnimationStart(Animation animation) {
               
            }
            
             public void onAnimationEnd(Animation animation) {
                Intent intent = new Intent(SplashScreen.this, Main.class);
                   SplashScreen.this.startActivity(intent);
                SplashScreen.this.finish();
             }

            public void onAnimationRepeat(Animation animation) {
               
            }
          });
   }
   
   @Override
   public void onPause() {
      ImageView gym = (ImageView) findViewById(R.id.imageView1);
      gym.clearAnimation();
      
      ImageView buddy = (ImageView) findViewById(R.id.imageView2);
      buddy.clearAnimation();
      
   }

}

Any ideas?
What's the stack trace? Crashes always have a stack trace, start your debugging from those. Can't do anything without it.
My app is live! If you have an android device please download and rate. It would be greatly appreciated! Smile
https://play.google.com/store/apps/details?id=com.creativecoders.gymbuddy&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5jcmVhdGl2ZWNvZGVycy5neW1idWRkeSJd
joshie75 wrote:
My app is live! If you have an android device please download and rate. It would be greatly appreciated! Smile
https://play.google.com/store/apps/details?id=com.creativecoders.gymbuddy&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5jcmVhdGl2ZWNvZGVycy5neW1idWRkeSJd


Protip, when taking screenshots make sure you don't have a theme installed (or use the emulator) - that font is horrible.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement