ERROR..........

Put your problem here if it does not fit any of the other categories.

ERROR..........

Postby gunaztar » Fri Feb 22, 2008 7:10 am

Hello plusminus,
you are doing really a great job..... Wishes for ur successive growth...
I got an error in friend finder application..... i cant resolve that... please tell me what is that... The error is [ Aplication error:org.me.Friend finder.Unable to start activity. Component info{org.me.FriendFinder}java.lang.Security Exception Permission android.permission,READ_CONTACTS required for provider contacts]..
Thank u
gunaztar
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Feb 20, 2008 12:40 pm

Top

Postby kiran » Fri Feb 22, 2008 9:18 am

You need permission to access contacts
Try adding
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission id="android.permission.READ_CONTACTS" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

to the Androidmainfest file.
using permissions are documented here
:) smile it is the key that fits the lock of everybody's heart
User avatar
kiran
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Thu Nov 22, 2007 11:36 am
Location: India

its there....

Postby gunaztar » Fri Feb 22, 2008 10:24 am

Still showing that same error.....
Already the uses permission is there .
gunaztar
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Feb 20, 2008 12:40 pm

Postby plusminus » Fri Feb 22, 2008 12:35 pm

Hello gunaztar,

since sdk-version m5 it is:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.READ_CONTACTS"/>
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Google needs to update that page.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Thanks for ur reply....

Postby gunaztar » Fri Feb 22, 2008 2:05 pm

Thanks for your reply.....
Now again showing the error.... Index out of bound exception...
This is the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.me.friend;
  2.  
  3.  
  4.  
  5. import java.text.DecimalFormat;
  6.  
  7. import java.util.ArrayList;
  8.  
  9. import java.util.List;
  10.  
  11. import java.util.regex.Matcher;
  12.  
  13. import java.util.regex.Pattern;
  14.  
  15.  
  16.  
  17. import android.app.ListActivity;
  18.  
  19. import android.content.Context;
  20.  
  21. import android.content.Intent;
  22.  
  23. import android.content.IntentFilter;
  24.  
  25. import android.content.IntentReceiver;
  26.  
  27. import android.database.Cursor;
  28.  
  29. import android.location.Location;
  30.  
  31. import android.location.LocationManager;
  32.  
  33. import android.location.LocationProvider;
  34.  
  35. import android.os.Bundle;
  36.  
  37. import android.provider.Contacts.People;
  38.  
  39. import android.view.Menu;
  40.  
  41. import android.widget.ArrayAdapter;
  42.  
  43.  
  44.  
  45. public class Friendfinder extends ListActivity {
  46.  
  47.      // ===========================================================
  48.  
  49.      // Fields
  50.  
  51.      // ===========================================================
  52.  
  53.      
  54.  
  55.      protected static final String MY_LOCATION_CHANGED_ACTION = new String("android.intent.action.LOCATION_CHANGED");
  56.  
  57.      protected LocationManager myLocationManager = null;
  58.  
  59.      protected Location myLocation = null;
  60.  
  61.      
  62.  
  63.      protected boolean doUpdates = true;
  64.  
  65.      MyIntentReceiver myIntentReceiver = null;
  66.  
  67.      protected final IntentFilter myIntentFilter =  new IntentFilter(MY_LOCATION_CHANGED_ACTION);
  68.  
  69.      
  70.  
  71.      protected final long MINIMUM_DISTANCECHANGE_FOR_UPDATE = 25; // in Meters
  72.  
  73.      protected final long MINIMUM_TIME_BETWEEN_UPDATE = 2500; // in Milliseconds
  74.  
  75.      
  76.  
  77.      /** Minimum distance in meters for a friend
  78.  
  79.       * to be recognize as a Friend to be drawn */
  80.  
  81.      protected static final int NEARFRIEND_MAX_DISTANCE = 10000000;  // 10.000km
  82.  
  83.      
  84.  
  85.      /** List of friends in */
  86.  
  87.      protected ArrayList<Friend> allFriends = new ArrayList<Friend>();
  88.  
  89.      
  90.  
  91.      // ===========================================================
  92.  
  93.      // Extra-Class
  94.  
  95.      // ===========================================================
  96.  
  97.  
  98.  
  99.  
  100.  
  101.      /**
  102.  
  103.       * This tiny IntentReceiver updates
  104.  
  105.       * our stuff as we receive the intents
  106.  
  107.       * (LOCATION_CHANGED_ACTION) we told the
  108.  
  109.       * myLocationManager to send to us.
  110.  
  111.       */
  112.  
  113.      class MyIntentReceiver extends IntentReceiver {
  114.  
  115.           @Override
  116.  
  117.           public void onReceiveIntent(Context context, Intent intent) {
  118.  
  119.                if(Friendfinder.this.doUpdates)
  120.  
  121.                     Friendfinder.this.updateList(); // Will simply update our list, when receiving an intent
  122.  
  123.           }
  124.  
  125.      }
  126.  
  127.  
  128.  
  129.      // ===========================================================
  130.  
  131.      // """Constructors""" (or the Entry-Point of it all)
  132.  
  133.      // ===========================================================
  134.  
  135.      /** Called when the activity is first created. */
  136.  
  137.      @Override
  138.  
  139.      public void onCreate(Bundle icicle) {
  140.  
  141.           super.onCreate(icicle);
  142.  
  143.  
  144.  
  145.           /* The first thing we need to do is to setup our own
  146.  
  147.            * locationManager, that will support us with our own gps data */
  148.  
  149.           this.myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  150.  
  151.  
  152.  
  153.           /* Update the list of our friends once on the start,
  154.  
  155.            * as they are not(yet) moving, no updates to them are necessary */
  156.  
  157.           this.refreshFriendsList();
  158.  
  159.          
  160.  
  161.           /* Initiate the update of the contactList
  162.  
  163.            * manually for the first time */
  164.  
  165.           this.updateList();
  166.  
  167.  
  168.  
  169.           /* Prepare the things, that will give
  170.  
  171.            * us the ability, to receive Information
  172.  
  173.            * about our GPS-Position. */
  174.  
  175.           this.setupForGPSAutoRefreshing();
  176.  
  177.      }
  178.  
  179.      
  180.  
  181.      /**
  182.  
  183.       * Restart the receiving, when we are back on line.
  184.  
  185.       */
  186.  
  187.      @Override
  188.  
  189.      public void onResume() {
  190.  
  191.           super.onResume();
  192.  
  193.           this.doUpdates = true;
  194.  
  195.          
  196.  
  197.           /* As we only want to react on the LOCATION_CHANGED
  198.  
  199.            * intents we made the OS send out, we have to
  200.  
  201.            * register it along with a filter, that will only
  202.  
  203.            * "pass through" on LOCATION_CHANGED-Intents.
  204.  
  205.            */
  206.  
  207.           this.registerReceiver(this.myIntentReceiver, this.myIntentFilter);
  208.  
  209.      }
  210.  
  211.      
  212.  
  213.      /**
  214.  
  215.       * Make sure to stop the animation when we're no longer on screen,
  216.  
  217.       * failing to do so will cause a lot of unnecessary cpu-usage!
  218.  
  219.       */
  220.  
  221.      @Override
  222.  
  223.      public void onFreeze(Bundle icicle) {
  224.  
  225.           this.doUpdates = false;
  226.  
  227.           this.unregisterReceiver(this.myIntentReceiver);
  228.  
  229.           super.onFreeze(icicle);
  230.  
  231.      }
  232.  
  233.  
  234.  
  235.      /** Register with our LocationManager to send us
  236.  
  237.       * an intent (who's Action-String we defined above)
  238.  
  239.       * when  an intent to the location manager,
  240.  
  241.       * that we want to get informed on changes to our own position.
  242.  
  243.       * This is one of the hottest features in Android.
  244.  
  245.       */
  246.  
  247.      private void setupForGPSAutoRefreshing() {
  248.  
  249.  
  250.  
  251.           // Get the first provider available
  252.  
  253.           List<LocationProvider> providers = this.myLocationManager.getProviders();
  254.  
  255.           LocationProvider provider = providers.get(0);
  256.  
  257.          
  258.  
  259.           this.myLocationManager.requestUpdates(provider, MINIMUM_TIME_BETWEEN_UPDATE,
  260.  
  261.                                                             MINIMUM_DISTANCECHANGE_FOR_UPDATE,
  262.  
  263.                                                             new Intent(MY_LOCATION_CHANGED_ACTION));
  264.  
  265.          
  266.  
  267.          
  268.  
  269.           /* Create an IntentReceiver, that will react on the
  270.  
  271.            * Intents we said to our LocationManager to send to us. */
  272.  
  273.           this.myIntentReceiver = new MyIntentReceiver();
  274.  
  275.  
  276.  
  277.           /*
  278.  
  279.            * In onResume() the following method will be called automatically!
  280.  
  281.            * registerReceiver(this.myIntentReceiver, this.myIntentFilter);
  282.  
  283.            */
  284.  
  285.      }
  286.  
  287.  
  288.  
  289.      /** Called only the first time the options menu is displayed.
  290.  
  291.       * Create the menu entries.
  292.  
  293.       *  Menus are added in the order they are hardcoded. */
  294.  
  295.      @Override
  296.  
  297.      public boolean onCreateOptionsMenu(Menu menu) {
  298.  
  299.           boolean supRetVal = super.onCreateOptionsMenu(menu);
  300.  
  301.           menu.add(0, 0, getString(R.string.main_menu_open_map));
  302.  
  303.           return supRetVal;
  304.  
  305.      }
  306.  
  307.      @Override
  308.  
  309.      public boolean onOptionsItemSelected(Menu.Item item) {
  310.  
  311.           switch (item.getId()) {
  312.  
  313.                case 0:
  314.  
  315.                     startSubActivity(new Intent(this, FriendFinderMap.class), 0);
  316.  
  317.                     return true;
  318.  
  319.           }
  320.  
  321.           return false;
  322.  
  323.      }
  324.  
  325.  
  326.  
  327.      // ===========================================================
  328.  
  329.      // Methods
  330.  
  331.      // ===========================================================
  332.  
  333.      
  334.  
  335.      private void refreshFriendsList(){
  336.  
  337.           Cursor c = getContentResolver().query(People.CONTENT_URI,
  338.  
  339.                     null, null, null, People.NAME + " ASC");
  340.  
  341.           /* This method allows the activity to take
  342.  
  343.          * care of managing the given Cursor's lifecycle
  344.  
  345.          * for you based on the activity's lifecycle. */
  346.  
  347.           startManagingCursor(c);
  348.  
  349.  
  350.  
  351.           int notesColumn = c.getColumnIndex(People.NOTES);
  352.  
  353.           int nameColumn = c.getColumnIndex(People.NAME);
  354.  
  355.          
  356.  
  357.           // Moves the cursor to the first row
  358.  
  359.           // and returns true if there is sth. to get
  360.  
  361.           if (c.first()) {
  362.  
  363.                do {      
  364.  
  365.                     String notesString = c.getString(notesColumn);
  366.  
  367.                    
  368.  
  369.                     Location friendLocation = null;
  370.  
  371.                     if (notesString != null) {
  372.  
  373.                          // Pattern for extracting geo-ContentURIs from the notes.
  374.  
  375.                          final String geoPattern = "(geo:[\\-]?[0-9]{1,3}\\.[0-9]{1,6}\\,[\\-]?[0-9]{1,3}\\.[0-9]{1,6}\\#)";
  376.  
  377.                          // Compile and use regular expression
  378.  
  379.                          Pattern pattern = Pattern.compile(geoPattern);
  380.  
  381.  
  382.  
  383.                          CharSequence inputStr = notesString;
  384.  
  385.                          Matcher matcher = pattern.matcher(inputStr);
  386.  
  387.  
  388.  
  389.                          boolean matchFound = matcher.find();
  390.  
  391.                          if (matchFound) {
  392.  
  393.                               // We take the first match available
  394.  
  395.                               String groupStr = matcher.group(0);
  396.  
  397.                               // And parse the Lat/Long-GeoPos-Values from it
  398.  
  399.                               friendLocation = new Location();
  400.  
  401.                               String latid = groupStr.substring(groupStr.indexOf(":") + 1,
  402.  
  403.                                         groupStr.indexOf(","));
  404.  
  405.                               String longit = groupStr.substring(groupStr.indexOf(",") + 1,
  406.  
  407.                                         groupStr.indexOf("#"));
  408.  
  409.                               friendLocation.setLongitude(Float.parseFloat(longit));
  410.  
  411.                               friendLocation.setLatitude(Float.parseFloat(latid));
  412.  
  413.                          }
  414.  
  415.                     }
  416.  
  417.                     String friendName = c.getString(nameColumn);
  418.  
  419.                     allFriends.add(new Friend(friendLocation, friendName));
  420.  
  421.                } while (c.next());
  422.  
  423.           }
  424.  
  425.      }
  426.  
  427.      
  428.  
  429.      private void updateList() {
  430.  
  431.           // Refresh our location...
  432.  
  433.           this.myLocation = myLocationManager.getCurrentLocation("gps");
  434.  
  435.          
  436.  
  437.           ArrayList<String> listItems = new ArrayList<String>();
  438.  
  439.          
  440.  
  441.           // For each Friend
  442.  
  443.           for(Friend aNearFriend : this.allFriends){
  444.  
  445.                /* Load the row-entry-format defined as a String
  446.  
  447.                 * and replace $name with the contact's name we
  448.  
  449.                 * get from the cursor */
  450.  
  451.                String curLine = new String(getString(R.string.main_list_format));
  452.  
  453.                curLine = curLine.replace("$name", aNearFriend.itsName);
  454.  
  455.                
  456.  
  457.                if(aNearFriend.itsLocation != null){
  458.  
  459.                     if( this.myLocation.distanceTo(aNearFriend.itsLocation) <
  460.  
  461.                                              NEARFRIEND_MAX_DISTANCE){
  462.  
  463.                          final DecimalFormat df = new DecimalFormat("####0.000");
  464.  
  465.                          String formattedDistance =
  466.  
  467.                               df.format(this.myLocation.distanceTo(
  468.  
  469.                                                   aNearFriend.itsLocation) / 1000);
  470.  
  471.                          curLine = curLine.replace("$distance", formattedDistance);
  472.  
  473.                     }
  474.  
  475.                }else{
  476.  
  477.                     curLine = curLine.replace("$distance",
  478.  
  479.                               getString(R.string.main_list_geo_not_set));
  480.  
  481.                }
  482.  
  483.                
  484.  
  485.                listItems.add(curLine);
  486.  
  487.           }
  488.  
  489.  
  490.  
  491.           ArrayAdapter<String> notes =  new ArrayAdapter<String>(this,
  492.  
  493.                     android.R.layout.simple_list_item_1, listItems);
  494.  
  495.  
  496.  
  497.           this.setListAdapter(notes);
  498.  
  499.      }
  500.  
  501. }
Parsed in 0.065 seconds, using GeSHi 1.0.8.4
gunaztar
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Feb 20, 2008 12:40 pm

Postby plusminus » Fri Feb 22, 2008 2:32 pm

on which line does the error occur :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby gunaztar » Fri Feb 22, 2008 3:03 pm

that only i dont know..... so only i send it to u..
no error during running process...
in emulator while opening the application its showing error array index out of bound exception
gunaztar
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Feb 20, 2008 12:40 pm

Postby res » Fri Feb 22, 2008 5:13 pm

gunaztar wrote:that only i dont know..... so only i send it to u..
no error during running process...
in emulator while opening the application its showing error array index out of bound exception


Run logcat to debug and view system messages
res
Senior Developer
Senior Developer
 
Posts: 146
Joined: Tue Nov 20, 2007 8:14 pm
Location: United States

Postby kaobiore » Mon Feb 25, 2008 12:33 pm

Hi!

gunaztar wrote:that only i dont know..... so only i send it to u..
no error during running process...
in emulator while opening the application its showing error array index out of bound exception


I guess I know why this error occurs ...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                  // Get the first provider available
  2.                  List<LocationProvider> providers = this.myLocationManager.getProviders();
  3.                  LocationProvider provider = providers.get(0);
  4.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


There are no LocationProviders visible for your application ... and thats the reason why "providers.get(0)" leads to an error.

You need to add some some permissions to your AndroidManifest.xml to be allowed to use the gps-service:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.ACCESS_LOCATION"></uses-permission>
  2. <uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission>
  3. <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"></uses-permission>
  4. <uses-permission android:name="android.permission.ACCESS_CELL_ID"></uses-permission>
  5.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


rgds
-=k=-
kaobiore
Freshman
Freshman
 
Posts: 8
Joined: Sat Dec 29, 2007 11:21 am
Location: Vienna / Austria

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests