1. Download our Official Android App: Forums for Android!

Apps Google using Activity's & Intents

Discussion in 'Android Development' started by JinDroid, Apr 6, 2011.

  1. JinDroid

    JinDroid Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    Hello Everyone

    i am trying to create a program to launch google webpage using intent's.
    The code compiles fine but I'm getting a force close when running

    could anyone point out whats causing this ?

    IntentActivity.Java
    Code (Text):
    1. package com.example.IntentActivity;
    2.  
    3. import android.app.Activity;
    4. import android.content.Intent;
    5. import android.net.Uri;
    6. import android.os.Bundle;
    7. import android.view.View;
    8. import android.view.View.OnClickListener;
    9. import android.widget.Button;
    10.  
    11.  
    12. public class IntentActivity extends Activity {
    13.     /** Called when the activity is first created. */
    14.     @Override
    15.     public void onCreate(Bundle savedInstanceState) {
    16.         super.onCreate(savedInstanceState);
    17.         setContentView(R.layout.main);
    18.        
    19.         final Button button = (Button) findViewById(R.id.button);
    20.         button.setOnClickListener(new OnClickListener() {
    21.             public void onClick(View v) {
    22.                 // Perform action on clicks
    23.                 Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
    24.                 startActivity(intent);
    25.                 finish();
    26.             }
    27.         });
    28.     }
    29. }


    Main.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent"
    6.     >
    7. <TextView  
    8.     android:layout_width="fill_parent"
    9.     android:layout_height="wrap_content"
    10.     android:text="@string/hello"
    11.     />
    12.     <Button
    13.         android:id="@+id/button"
    14.         android:layout_width="wrap_content"
    15.         android:layout_height="wrap_content"
    16.         android:padding="10dp"
    17.         android:text="ButtonText" />
    18.             <Button
    19.         android:id="@+id/button"
    20.         android:layout_width="wrap_content"
    21.         android:layout_height="wrap_content"
    22.         android:padding="10dp"
    23.         android:text="Button2Text" />
    24. </LinearLayout>
    25.  


    Strings.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources>
    3.     <string name="hello">Hello World, IntentActivity!</string>
    4.     <string name="app_name">Intent,Activity</string>
    5.     <string name="NewTitle">Activity Using Intent Object</string>
    6.     <string name="ButtonText">Start Browser</string>
    7.     <string name="Button2Text">Start Activity</string>
    8. </resources>
    9.  



    IntentActivityManifest
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.       package="com.example.IntentActivity"
    5.       android:versionCode="1"
    6.       android:versionName="1.0">
    7.  
    8.  
    9.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    10.         <activity android:name=".IntentActivity"
    11.                   android:label="@string/NewTitle">
    12.             <intent-filter>
    13.                 <action android:name="android.intent.action.MAIN" />
    14.                 <category android:name="android.intent.category.LAUNCHER" />
    15.             </intent-filter>
    16.         </activity>
    17.         <activity android:name=".NewActivity"
    18.                   android:label="@string/app_name"
    19.                   android:theme= "@android:style/Theme.Dialog">
    20.         </activity>
    21.     </application>
    22. </manifest>
     

    Advertisement

  2. JamTheMan

    JamTheMan Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    136
    Joined:
    Dec 16, 2010

    What does the LogCat say about the error?
     
  3. JinDroid

    JinDroid Guest
    Thread Starter
    Rank:
    None
    Posts:
    0
    Joined:

    sorry could you explain this logcat ? never heard of it ?
     

Share This Page

Loading...