rainBarrel
New Member
After building a basic calculator I am trying to build an android app that opens the URL set in an edittext field o the android browser.Conceptually it sounded easy,but for me,it was far from it.my java Code\[code\]package com.example;import android.app.Activity;import android.content.DialogInterface;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.view.View.OnClickListener;public class Access extends Activity implements OnClickListener { /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn=(Button) findViewById(R.id.btn); btn.setOnClickListener(this); } public void onClick(View view){ EditText browse =(EditText)findViewById(R.id.btn1); Intent i = new Intent("android.intent.action.VIEW", Uri.parse(browse.getText().toString())); startActivity(i); }}\[/code\]My xml DEsign\[code\]<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" androidrientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/url" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Enter webpage to go" /> <EditText android:id="@+id/btn1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/radioGroup1" androidnClick="onClick" android:text="Browse" /></LinearLayout>\[/code\]And my logcat error\[code\]09-28 11:31:13.615: ERROR/StrictMode(92): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. java.lang.Throwable: Explicit termination method 'close' not called at dalvik.system.CloseGuard.open(CloseGuard.java:184) at java.io.FileInputStream.<init>(FileInputStream.java:80) at com.android.server.pm.UserManager.readUserList(UserManager.java:114) at com.android.server.pm.UserManager.<init>(UserManager.java:81) at com.android.server.pm.UserManager.<init>(UserManager.java:85) at com.android.server.pm.PackageManagerService.<init>(PackageManagerService.java:923) at com.android.server.pm.PackageManagerService.main(PackageManagerService.java:833) at com.android.server.ServerThread.run(SystemServer.java:163)09-28 11:31:21.256: ERROR/SoundPool(92): error loading /system/media/audio/ui/Lock.ogg09-28 11:31:21.256: ERROR/SoundPool(92): error loading /system/media/audio/ui/Unlock.ogg09-28 11:31:21.435: ERROR/EventHub(92): could not get driver version for /dev/input/mouse0, Not a typewriter09-28 11:31:21.465: ERROR/EventHub(92): could not get driver version for /dev/input/mice, Not a typewriter09-28 11:31:21.814: ERROR/CommandListener(33): Failed to open /proc/sys/net/ipv6/conf/wlan0/disable_ipv6: No such file or directory09-28 11:31:21.814: ERROR/WifiStateMachine(92): Failed to disable IPv6: java.lang.IllegalStateException: Unable to communicate to native daemon for disabling ipv609-28 11:31:21.904: ERROR/MobileDataStateTracker(92): default: Ignoring feature request because could not acquire PhoneService09-28 11:31:21.904: ERROR/MobileDataStateTracker(92): default: Could not enable APN type "default"09-28 11:31:30.305: ERROR/ActivityThread(185): Failed to find provider info for com.android.inputmethod.latin.dictionarypack09-28 11:31:30.315: ERROR/BinaryDictionaryGetter(185): Could not find a dictionary pack09-28 11:31:39.365: ERROR/SoundPool(92): error loading /system/media/audio/ui/Effect_Tick.ogg09-28 11:31:39.365: ERROR/SoundPool(92): error loading /system/media/audio/ui/Effect_Tick.ogg09-28 11:31:39.365: ERROR/SoundPool(92): error loading /system/media/audio/ui/Effect_Tick.ogg09-28 11:31:39.404: ERROR/SoundPool(92): error loading /system/media/audio/ui/Effect_Tick.ogg09-28 11:31:39.404: ERROR/SoundPool(92): error loading /system/media/audio/ui/Effect_Tick.ogg09-28 11:31:39.404: ERROR/SoundPool(92): error loading /system/media/audio/ui/KeypressStandard.ogg09-28 11:31:39.414: ERROR/SoundPool(92): error loading /system/media/audio/ui/KeypressSpacebar.ogg09-28 11:31:39.414: ERROR/SoundPool(92): error loading /system/media/audio/ui/KeypressDelete.ogg09-28 11:31:40.074: ERROR/SoundPool(92): error loading /system/media/audio/ui/KeypressReturn.ogg09-28 11:32:01.754: ERROR/DefaultVoicemailNotifier(291): No voicemails to notify about: clear the notification.09-28 11:32:23.674: ERROR/AndroidRuntime(583): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.Access}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button at com.example.Access.onCreate(Access.java:26) at android.app.Activity.performCreate(Activity.java:4465) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) ... 11 more\[/code\]