Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old January 11th, 2012, 02:25 AM   #1 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Where is my error?

Hi

scorpi10 is offline  
Reply With Quote
Sponsors
Old January 11th, 2012, 02:25 AM   #2 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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ıcı</string>
    <string name="app_name">Android Web Tarayicim</string>
    <string name="ileri">İ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.
scorpi10 is offline  
Reply With Quote
Old January 11th, 2012, 03:21 AM   #3 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

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.
jiminaus is offline  
Reply With Quote
Old January 11th, 2012, 12:25 PM   #4 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It has not a logcat report or LintWarnings.
Attached Images
File Type: bmp Android error.bmp (122.7 KB, 5 views)
scorpi10 is offline  
Reply With Quote
Old January 11th, 2012, 12:41 PM   #5 (permalink)
Junior Member
 
Lemoncog's Avatar
 
Join Date: Feb 2011
Posts: 25
 
Device(s): HTC Desire HD
Thanks: 0
Thanked 6 Times in 2 Posts
Default

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.
Lemoncog is offline  
Reply With Quote
Old January 11th, 2012, 02:34 PM   #6 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

What development environment are you using? How are you running your app?

When does it crash? Immediately on startup? After you do something?
jiminaus is offline  
Reply With Quote
Old January 11th, 2012, 03:22 PM   #7 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
scorpi10 is offline  
Last edited by scorpi10; January 11th, 2012 at 03:33 PM.
Reply With Quote
Old January 12th, 2012, 12:33 AM   #8 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
scorpi10 is offline  
Reply With Quote
Old January 12th, 2012, 12:39 AM   #9 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

You haven't provided the code for com.Web_Tarayici.Web_TarayiciActivity. What's on line 41 of Web_TarayiciActivity.java?
jiminaus is offline  
Last edited by jiminaus; January 12th, 2012 at 12:45 AM. Reason: Nuked previous instructions on how to get exception trace from LogCat.
Reply With Quote
Old January 12th, 2012, 01:12 AM   #10 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I opened alike project in another name Web_TarayiciActivity.And compiled this project.Namely alike codes.
scorpi10 is offline  
Reply With Quote
Sponsors
Old January 12th, 2012, 02:06 AM   #11 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

I don't understand what this means.
jiminaus is offline  
Reply With Quote
Old January 12th, 2012, 02:51 AM   #12 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Web_TarayiciActivity project=this project
this=Web_TarayiciActivity
scorpi10 is offline  
Reply With Quote
Old January 12th, 2012, 03:02 AM   #13 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

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.
jiminaus is offline  
Last edited by jiminaus; January 12th, 2012 at 03:10 AM.
Reply With Quote
Old January 12th, 2012, 05:48 PM   #14 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 9
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes.It works fine.Thank u for ur helps.This is java's basic rule.But i forgot it
scorpi10 is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:22 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo