Intent Contact API ( Force Close ) ERROR !

Tutorials with advanced 'difficulty' and more Lines of Code.

Intent Contact API ( Force Close ) ERROR !

Postby Sivan » Sat Dec 18, 2010 5:23 pm

hi...

Iam trying a simple intent where u click the button and it Open's the Contact Book....

I wrote down the java code and i did'nt hav any error with the project in eclipse...

But when i run it in the emulator , the app is force closing..

This is the java code :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.friend.finder;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9.  
  10. public class Friend extends Activity {
  11.     /** Called when the activity is first created. */
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.main);
  16.        
  17. Button widget39  = (Button)findViewById(R.id.widget39);    
  18.        
  19.         widget39.setOnClickListener(new Button.OnClickListener() {
  20.  
  21.                         @Override
  22.                         public void onClick(View v) {
  23.                                 Intent myIntent = new Intent();
  24.                                
  25.                                 myIntent.setAction(Intent.ACTION_VIEW);
  26.                                 myIntent.setData(android.provider.Contacts.People.CONTENT_URI);
  27.                                 startActivity(myIntent);
  28.                         }
  29.         });
  30.                        
  31.        
  32.     }
  33. }
  34.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


This is the XML code..
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <AbsoluteLayout
  3. android:id="@+id/widget38"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. xmlns:android="http://schemas.android.com/apk/res/android"
  7. >
  8. <TextView
  9. android:id="@+id/widget37"
  10. android:layout_width="125px"
  11. android:layout_height="22px"
  12. android:text="Selected Contact :"
  13. android:layout_x="9px"
  14. android:layout_y="72px"
  15. >
  16. </TextView>
  17. <TextView
  18. android:id="@+id/widget39"
  19. android:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:text="No contact Selected yet ."
  22. android:layout_x="131px"
  23. android:layout_y="72px"
  24. >
  25. </TextView>
  26. <Button
  27. android:id="@+id/widget40"
  28. android:layout_width="146px"
  29. android:layout_height="48px"
  30. android:text="Pick Contact"
  31. android:layout_x="12px"
  32. android:layout_y="15px"
  33. >
  34. </Button>
  35. </AbsoluteLayout>
  36.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


And the Manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.friend.finder"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".Friend"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>

</manifest>

The Emulator is Android OS 2.3


If there is any way to fix this ???

Please Help...
Sivan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 05, 2010 10:02 am
Location: Bangalore , India

Top

Re: Intent Contact API ( Force Close ) ERROR !

Postby Exoit » Sun Dec 19, 2010 1:09 am

You are casting your TextView (R.id.widget39) to a Button and then trying to use it as one. This is why it force closes, and you should not use android.provider.Contacts anymore because it's been deprecated since 2.0, instead use ContactsContract.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Friend extends Activity {
  2.     /** Called when the activity is first created. */
  3.     @Override
  4.     public void onCreate(Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.         setContentView(R.layout.main);
  7.        
  8.         Button widget40  = (Button)findViewById(R.id.widget40);    
  9.        
  10.         widget40.setOnClickListener(new Button.OnClickListener() {
  11.  
  12.                         @Override
  13.                         public void onClick(View v) {
  14.                                 Intent myIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
  15.                                 startActivity(myIntent);
  16.                         }
  17.         });
  18.                        
  19.        
  20.     }
  21. }
  22.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Exoit
Freshman
Freshman
 
Posts: 4
Joined: Sun Dec 19, 2010 1:00 am

Re: Intent Contact API ( Force Close ) ERROR !

Postby Sivan » Sun Dec 19, 2010 10:41 am

Thanks man...

Really helped me..
I realized my mistakes....

NO Errors now ...
Sivan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 05, 2010 10:02 am
Location: Bangalore , India

Re: Intent Contact API ( Force Close ) ERROR !

Postby Sivan » Wed Dec 22, 2010 5:29 pm

Please can u upload the java code again ? pleezz

When i tried it on my Mac Pro, I did'nt get any error....
But now on my Windows Machine , when i cme to this topic page , In the code uv'e uploded its showning sme
<span class="posthilit">Intent</span>

When i try it it has an error ...

Pleezzz upload again ....
Sivan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 05, 2010 10:02 am
Location: Bangalore , India

Re: Intent Contact API ( Force Close ) ERROR !

Postby Sivan » Wed Dec 22, 2010 5:59 pm

Sorry man
Browser Issue
Tats why it displayed " <span class="posthilit">Intent</span>"
Just reseted browser..
Got it all right

Thank you very much....
Sivan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 05, 2010 10:02 am
Location: Bangalore , India

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests