Android web browser application stopping. Unable to start activity

I'm trying to make a simple web browser for my android development class and every time I try to run the app I get the message "Unfortunately, Navegador has stopped".

I followed my teacher's code and everyone in my class could run it without problems. I'm starting to think the problem might be on my computer.

I'm using Eclipse. Some variables on the code are in spanish.

Here's my activity_main.xml Basically it has 4 buttons

  • Atras (Backward)
  • Adelante (Forward)
  • Actualizar (Refresh)
  • Ir (Go to website)

    <Button 
     android:id="@+id/btAtras"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="top"
     android:layout_weight="3"
     android:text="Atras"
        />
    
    <Button 
     android:id="@+id/btAdelante"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="top"
     android:layout_weight="3"
     android:text="Adelante"
        />
    
    <Button 
     android:id="@+id/btActualizar"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="top"
     android:layout_weight="3"
     android:text="Actualizar"
        />
    

Here's my MainActivity.java

package com.curso.navegador;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener{


    EditText navegador;
    Button ir, atras, adelante, actualizar, borrar;
    WebView sitio;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sitio = (WebView) findViewById (R.id.wvNavegador);
        sitio.setWebViewClient(new ViewClient());
        sitio.getSettings().setJavaScriptEnabled(true);
        sitio.getSettings().setLoadWithOverviewMode(true);
        sitio.getSettings().setUseWideViewPort(true);

        navegador = (EditText) findViewById (R.id.wvNavegador);
        ir =(Button) findViewById (R.id.btIr);
        atras =(Button) findViewById (R.id.btAtras);
        adelante =(Button) findViewById (R.id.btAdelante);
        actualizar = (Button) findViewById (R.id.btActualizar);

        ir.setOnClickListener(this);
        atras.setOnClickListener(this);
        adelante.setOnClickListener(this);
        actualizar.setOnClickListener(this);
        borrar.setOnClickListener(this);

        sitio.loadUrl("");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.btIr:
            String web = navegador.getText().toString();
            sitio.loadUrl(web);
            break;
        case R.id.btAtras:
            if(sitio.canGoBack())
                sitio.goBack();
            break;
        case R.id.btAdelante:
            if(sitio.canGoForward())
                sitio.goForward();
            break;
        case R.id.btActualizar:
            sitio.reload();
            break;
        }
    }
}

And we added this additional ViewClient.java class

package com.curso.navegador;

import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ViewClient extends WebViewClient{
    public boolean shouldOverrideUrlLading(WebView v, String url){
        v.loadUrl(url);
        return true;
    }
}

In addition I added the permission on android manifest android.permission.INTERNET

03-11 12:07:15.289: E/AndroidRuntime(27901): FATAL EXCEPTION: main
03-11 12:07:15.289: E/AndroidRuntime(27901): Process: com.curso.navegador, PID: 27901
03-11 12:07:15.289: E/AndroidRuntime(27901): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.curso.navegador/com.curso.navegador.MainActivity}: java.lang.ClassCastException: android.webkit.WebView cannot be cast to android.widget.EditText
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.os.Looper.loop(Looper.java:148)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.ActivityThread.main(ActivityThread.java:5443)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at java.lang.reflect.Method.invoke(Native Method)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-11 12:07:15.289: E/AndroidRuntime(27901): Caused by: java.lang.ClassCastException: android.webkit.WebView cannot be cast to android.widget.EditText
03-11 12:07:15.289: E/AndroidRuntime(27901):    at com.curso.navegador.MainActivity.onCreate(MainActivity.java:30)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.Activity.performCreate(Activity.java:6245)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
03-11 12:07:15.289: E/AndroidRuntime(27901):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
03-11 12:07:15.289: E/AndroidRuntime(27901):    ... 9 more

It's getting really frustrating because I'm getting this same type of error every time I start a new android application and this didn't happen before and I haven't found a solution yet.

I would appreciate very much your help.

Answers


The stack trace is telling you what the problem is. You are trying to cast a WebView to an EditText. Based on what you have provided its this line

navegador = (EditText) findViewById (R.id.wvNavegador);

You are first casting wvNavegador to a webview few lines above and then to an edit text, which is obviously a problem.


Need Your Help

React-Native after DataSource update empty screen

listview datasource react-native

I have a ListView with some elements, and a button that hides some elements of the list when pressed.

Will CLOB data be truncated when displayed in a SELECT query? If so, how can it be displayed?

asp.net oracle clob

I've got a Varchar2 field in my table which I want to convert to a CLOB. I am unsure whether the data would get truncated when selected. If so, what is the limit and does it depend on the database