Problem with Inner Classes


Last Updated:

  1. andravis

    andravis New Member This Topic's Starter

    Joined:
    Apr 14, 2010
    Messages:
    2
    Likes Received:
    0
    hey everyone,

    i'm pretty new to programming for android, i'm using eclipse as my ide, and i'm having difficulty with anonymous inner classes. for instance, i'll simply copy/paste example code from android.com or write my own code and everything goes fine until i reach an anonymous class.

    for example, i've copied/pasted the following from android.com:

    lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {
    // When clicked, show a toast with the TextView text
    Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
    Toast.LENGTH_SHORT).show();
    }
    });

    and the error occurs with OnItemClickListener() { ... on the first line. the problem description in eclipse reads, "OnItemClickListener cannot be resolved to a type."

    any suggestions?

    thanks everyone,

    andrew
     

    Advertisement
  2. dmitriyk

    dmitriyk Active Member

    Joined:
    Apr 17, 2010
    Messages:
    44
    Likes Received:
    10
    The problem isn't with the inner class per-se; the problem is that Java can't find OnItemClickListener. Make sure you either import it at the top of the file with "import android.widget.AdapterView.OnItemClickListener;" or define your inner class as "...new android.widget.AdapterView.OnItemClickListener()..."
     
  3. shelarsheetal

    shelarsheetal New Member

    Joined:
    Aug 25, 2011
    Messages:
    3
    Likes Received:
    0
    main cannot b resolve to the type
     
  4. shelarsheetal

    shelarsheetal New Member

    Joined:
    Aug 25, 2011
    Messages:
    3
    Likes Received:
    0
    what is the solution to the above error sentence?
     
  5. shelarsheetal

    shelarsheetal New Member

    Joined:
    Aug 25, 2011
    Messages:
    3
    Likes Received:
    0
    Hi I'm trying some of the Android applications for practice purpose, but i'm facing a lof of problems while development, the most common problem is- id/main cannot b resolve to the type, can i get a proper suggestion for my query. Also m working on Linux n while runnig my application i see that it takes purely 5mins for a emulator to show the output, so i just wanted to know that is it usual with Linux???
     

Share This Page

Loading...