• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Where is my error?

I want to add buttons and a textedit in this example:
Web View | Android Developers

HelloWebView2.java:
Code:
package com.HelloWebView2;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
public class HelloWebView2Activity extends Activity {
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
    /** Called when the activity is first created. */
    
    Button ileriTusu,geriTusu,DurTusu,GitTusu,AramaTusu;
   TextView AdresCubugu;
    WebView WebEkrani;
    String ilksayfa;
    String sayfa;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ileriTusu=(Button)findViewById(R.id.ileritusu);
        geriTusu=(Button)findViewById(R.id.geritusu);
        DurTusu=(Button)findViewById(R.id.Dur);
        GitTusu=(Button)findViewById(R.id.Git);
        AramaTusu=(Button)findViewById(R.id.Arama);
        AdresCubugu=(TextView)findViewById(R.id.Adres);
        WebEkrani=(WebView)findViewById(R.id.Ekran);
        WebEkrani.getSettings().setJavaScriptEnabled(true);
        WebEkrani.setWebViewClient(new HelloWebViewClient());
        sayfa=(String) AdresCubugu.getText();
    
        
        GitTusu.setOnTouchListener(new View.OnTouchListener() {
            
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                WebEkrani.loadUrl((String) AdresCubugu.getText());    
                WebEkrani.setWebViewClient(new HelloWebViewClient());
                return true;
                
                
            }
            
        }); 
        geriTusu.setOnTouchListener(new View.OnTouchListener() {
            
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if(WebEkrani.canGoBack())
                WebEkrani.goBack();
                return true;
                
                }
        });
ileriTusu.setOnTouchListener(new View.OnTouchListener() {
    
    public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if(WebEkrani.canGoForward())
                WebEkrani.goForward();
                return true;
                }
        });

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && WebEkrani.canGoBack()) {
            WebEkrani.goBack();
            return true;
        }
        if ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && WebEkrani.canGoForward()) {
            WebEkrani.goForward();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

main.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Zemin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:text="@string/hello" >

    <EditText
        android:id="@+id/Adres"
        android:layout_width="265dp"
        android:layout_height="45dp"
        android:layout_margin="1dp" />

    <ProgressBar
        android:id="@+id/Dolum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/ileritusu"
        android:layout_width="71dp"
        android:layout_height="45dp"
        android:layout_marginTop="41dp" 
        android:layout_marginLeft="-320dp"
        android:text="@string/ileri" />
     <Button
        android:id="@+id/geritusu"
        android:layout_width="71dp"
        android:layout_height="45dp"
        android:layout_marginTop="41dp" 
        android:layout_marginLeft="-8dp" 
        android:text="@string/geri"
        />
      <Button
        android:id="@+id/Git"
        android:layout_width="71dp"
        android:layout_height="45dp"
        android:layout_marginTop="41dp" 
        android:layout_marginLeft="-8dp" 
        android:text="@string/git"
        />

      <Button
          android:id="@+id/Dur"
          android:layout_width="71dp"
          android:layout_height="45dp"
          android:layout_marginLeft="-8dp"
          android:layout_marginTop="41dp"
          android:text="@string/dur" />
      <Button
          android:id="@+id/Arama"
          android:layout_width="71dp"
          android:layout_height="45dp"
          android:layout_marginLeft="-8dp"
          android:layout_marginTop="41dp"
          android:text="@string/arama" />
    <WebView
          android:id="@+id/Ekran"
          android:layout_marginTop="82dp"
          android:layout_width="317dp"
          android:layout_height="400dp"
          android:layout_marginLeft="-323dp"
        />
</LinearLayout>

string.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Web Taray&#305;c&#305;</string>
    <string name="app_name">Android Web Tarayicim</string>
    <string name="ileri">&#304;leri</string>
    <string name="geri">Geri</string>
    <string name="git">Git</string>
    <string name="dur">Dur</string>
    <string name="arama">Arama</string>

</resources>

R.java:
Code:
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.HelloWebView2;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int Adres=0x7f050001;
        public static final int Arama=0x7f050007;
        public static final int Dolum=0x7f050002;
        public static final int Dur=0x7f050006;
        public static final int Ekran=0x7f050008;
        public static final int Git=0x7f050005;
        public static final int Zemin=0x7f050000;
        public static final int geritusu=0x7f050004;
        public static final int ileritusu=0x7f050003;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int arama=0x7f040006;
        public static final int dur=0x7f040005;
        public static final int geri=0x7f040003;
        public static final int git=0x7f040004;
        public static final int hello=0x7f040000;
        public static final int ileri=0x7f040002;
    }
}

AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.HelloWebView2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity android:name=".HelloGoogleMaps" android:label="@string/app_name"
     android:theme="@android:style/Theme.NoTitleBar"/>
        <activity
            android:name=".HelloWebView2Activity"
            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>

</manifest>

This is running true.But i take "force close" error in emulator.
 
In the LogCat view of Eclipse, you should see a trace of the exception that crashed your application. Post that exception trace. It will help us to figure out what's wrong.
 
What you need to do is put breakpoints in your code by double clicking the left side of your code. Then you can step through your code and find where the exception is coming from and resolve it.
 
What development environment are you using? How are you running your app?

When does it crash? Immediately on startup? After you do something?
 
I Exceptioned.This is Lint Warnings:
Code:
Message:  
This text field does not specify an inputType or a hint. 
Missing density variation folders in res: drawable-xhdi                                  

File: 
main.xml  
Web_Tarayici                                 

Line:
  9
  1
I am using eclipse.Android 2.2. Crashing when immediately on startup.
 
Ah sorry.I forgot to give LogCat reports:
Code:
01-12 06:31:53.984: D/AndroidRuntime(283): Shutting down VM
01-12 06:31:53.984: W/dalvikvm(283): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-12 06:31:54.044: E/AndroidRuntime(283): FATAL EXCEPTION: main
01-12 06:31:54.044: E/AndroidRuntime(283): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Web_Tarayici/com.Web_Tarayici.Web_TarayiciActivity}: java.lang.ClassCastException: android.text.SpannableStringBuilder
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.os.Looper.loop(Looper.java:123)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-12 06:31:54.044: E/AndroidRuntime(283):     at java.lang.reflect.Method.invokeNative(Native Method)
01-12 06:31:54.044: E/AndroidRuntime(283):     at java.lang.reflect.Method.invoke(Method.java:521)
01-12 06:31:54.044: E/AndroidRuntime(283):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-12 06:31:54.044: E/AndroidRuntime(283):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-12 06:31:54.044: E/AndroidRuntime(283):     at dalvik.system.NativeStart.main(Native Method)
01-12 06:31:54.044: E/AndroidRuntime(283): Caused by: java.lang.ClassCastException: android.text.SpannableStringBuilder
01-12 06:31:54.044: E/AndroidRuntime(283):     at com.Web_Tarayici.Web_TarayiciActivity.onCreate(Web_TarayiciActivity.java:41)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-12 06:31:54.044: E/AndroidRuntime(283):     ... 11 more
 
You haven't provided the code for com.Web_Tarayici.Web_TarayiciActivity. What's on line 41 of Web_TarayiciActivity.java?
 
In that case, the problematic line is:
Code:
sayfa=(String) AdresCubugu.getText();

You're trying to cast a android.text.SpannableStringBuilder to a java.lang.String, and this isn't possible because the former isn't a subclass of the later.

Try:
Code:
sayfa=AdresCubugu.getText().toString();


EDIT: And similarly on line 48.
 
Back
Top Bottom