J
JinDroid
Guest
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
Main.xml
Strings.xml
IntentActivityManifest
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:
package com.example.IntentActivity;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class IntentActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(intent);
finish();
}
});
}
}
Main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="ButtonText" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Button2Text" />
</LinearLayout>
Strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, IntentActivity!</string>
<string name="app_name">Intent,Activity</string>
<string name="NewTitle">Activity Using Intent Object</string>
<string name="ButtonText">Start Browser</string>
<string name="Button2Text">Start Activity</string>
</resources>
IntentActivityManifest
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.IntentActivity"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".IntentActivity"
android:label="@string/NewTitle">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NewActivity"
android:label="@string/app_name"
android:theme= "@android:style/Theme.Dialog">
</activity>
</application>
</manifest>