1. Download our Official Android App: Forums for Android!

Apps Where is my error?

Discussion in 'Android Development' started by scorpi10, Jan 11, 2012.

  1. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    Hi
     

    Advertisement

  2. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    I want to add buttons and a textedit in this example:
    Web View | Android Developers

    HelloWebView2.java:
    Code (Text):
    1.  
    2. package com.HelloWebView2;
    3.  
    4. import android.app.Activity;
    5. import android.os.Bundle;
    6. import android.view.KeyEvent;
    7. import android.view.MotionEvent;
    8. import android.view.View;
    9. import android.webkit.WebView;
    10. import android.webkit.WebViewClient;
    11. import android.widget.Button;
    12. import android.widget.TextView;
    13. public class HelloWebView2Activity extends Activity {
    14.     private class HelloWebViewClient extends WebViewClient {
    15.         @Override
    16.         public boolean shouldOverrideUrlLoading(WebView view, String url) {
    17.             view.loadUrl(url);
    18.             return true;
    19.         }
    20.     }
    21.     /** Called when the activity is first created. */
    22.    
    23.     Button ileriTusu,geriTusu,DurTusu,GitTusu,AramaTusu;
    24.    TextView AdresCubugu;
    25.     WebView WebEkrani;
    26.     String ilksayfa;
    27.     String sayfa;
    28.    
    29.     @Override
    30.     public void onCreate(Bundle savedInstanceState) {
    31.         super.onCreate(savedInstanceState);
    32.         setContentView(R.layout.main);
    33.         ileriTusu=(Button)findViewById(R.id.ileritusu);
    34.         geriTusu=(Button)findViewById(R.id.geritusu);
    35.         DurTusu=(Button)findViewById(R.id.Dur);
    36.         GitTusu=(Button)findViewById(R.id.Git);
    37.         AramaTusu=(Button)findViewById(R.id.Arama);
    38.         AdresCubugu=(TextView)findViewById(R.id.Adres);
    39.         WebEkrani=(WebView)findViewById(R.id.Ekran);
    40.         WebEkrani.getSettings().setJavaScriptEnabled(true);
    41.         WebEkrani.setWebViewClient(new HelloWebViewClient());
    42.         sayfa=(String) AdresCubugu.getText();
    43.    
    44.        
    45.         GitTusu.setOnTouchListener(new View.OnTouchListener() {
    46.            
    47.             public boolean onTouch(View v, MotionEvent event) {
    48.                 // TODO Auto-generated method stub
    49.                 WebEkrani.loadUrl((String) AdresCubugu.getText());    
    50.                 WebEkrani.setWebViewClient(new HelloWebViewClient());
    51.                 return true;
    52.                
    53.                
    54.             }
    55.            
    56.         });
    57.         geriTusu.setOnTouchListener(new View.OnTouchListener() {
    58.            
    59.             public boolean onTouch(View v, MotionEvent event) {
    60.                 // TODO Auto-generated method stub
    61.                 if(WebEkrani.canGoBack())
    62.                 WebEkrani.goBack();
    63.                 return true;
    64.                
    65.                 }
    66.         });
    67. ileriTusu.setOnTouchListener(new View.OnTouchListener() {
    68.    
    69.     public boolean onTouch(View v, MotionEvent event) {
    70.                 // TODO Auto-generated method stub
    71.                 if(WebEkrani.canGoForward())
    72.                 WebEkrani.goForward();
    73.                 return true;
    74.                 }
    75.         });
    76.  
    77.     }
    78.     @Override
    79.     public boolean onKeyDown(int keyCode, KeyEvent event) {
    80.         if ((keyCode == KeyEvent.KEYCODE_BACK) && WebEkrani.canGoBack()) {
    81.             WebEkrani.goBack();
    82.             return true;
    83.         }
    84.         if ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && WebEkrani.canGoForward()) {
    85.             WebEkrani.goForward();
    86.             return true;
    87.         }
    88.         return super.onKeyDown(keyCode, event);
    89.     }
    90. }
    91.  
    main.xml:
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:id="@+id/Zemin"
    5.     android:layout_width="wrap_content"
    6.     android:layout_height="wrap_content"
    7.     android:baselineAligned="false"
    8.     android:text="@string/hello" >
    9.  
    10.     <EditText
    11.         android:id="@+id/Adres"
    12.         android:layout_width="265dp"
    13.         android:layout_height="45dp"
    14.         android:layout_margin="1dp" />
    15.  
    16.     <ProgressBar
    17.         android:id="@+id/Dolum"
    18.         android:layout_width="wrap_content"
    19.         android:layout_height="wrap_content" />
    20.  
    21.     <Button
    22.         android:id="@+id/ileritusu"
    23.         android:layout_width="71dp"
    24.         android:layout_height="45dp"
    25.         android:layout_marginTop="41dp"
    26.         android:layout_marginLeft="-320dp"
    27.         android:text="@string/ileri" />
    28.      <Button
    29.         android:id="@+id/geritusu"
    30.         android:layout_width="71dp"
    31.         android:layout_height="45dp"
    32.         android:layout_marginTop="41dp"
    33.         android:layout_marginLeft="-8dp"
    34.         android:text="@string/geri"
    35.         />
    36.       <Button
    37.         android:id="@+id/Git"
    38.         android:layout_width="71dp"
    39.         android:layout_height="45dp"
    40.         android:layout_marginTop="41dp"
    41.         android:layout_marginLeft="-8dp"
    42.         android:text="@string/git"
    43.         />
    44.  
    45.       <Button
    46.           android:id="@+id/Dur"
    47.           android:layout_width="71dp"
    48.           android:layout_height="45dp"
    49.           android:layout_marginLeft="-8dp"
    50.           android:layout_marginTop="41dp"
    51.           android:text="@string/dur" />
    52.       <Button
    53.           android:id="@+id/Arama"
    54.           android:layout_width="71dp"
    55.           android:layout_height="45dp"
    56.           android:layout_marginLeft="-8dp"
    57.           android:layout_marginTop="41dp"
    58.           android:text="@string/arama" />
    59.     <WebView
    60.           android:id="@+id/Ekran"
    61.           android:layout_marginTop="82dp"
    62.           android:layout_width="317dp"
    63.           android:layout_height="400dp"
    64.           android:layout_marginLeft="-323dp"
    65.         />
    66. </LinearLayout>
    67.  
    string.xml:
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <resources>
    4.  
    5.     <string name="hello">Web Taray&#305;c&#305;</string>
    6.     <string name="app_name">Android Web Tarayicim</string>
    7.     <string name="ileri">&#304;leri</string>
    8.     <string name="geri">Geri</string>
    9.     <string name="git">Git</string>
    10.     <string name="dur">Dur</string>
    11.     <string name="arama">Arama</string>
    12.  
    13. </resources>
    14.  
    R.java:
    Code (Text):
    1.  
    2. /* AUTO-GENERATED FILE.  DO NOT MODIFY.
    3.  *
    4.  * This class was automatically generated by the
    5.  * aapt tool from the resource data it found.  It
    6.  * should not be modified by hand.
    7.  */
    8.  
    9. package com.HelloWebView2;
    10.  
    11. public final class R {
    12.     public static final class attr {
    13.     }
    14.     public static final class drawable {
    15.         public static final int ic_launcher=0x7f020000;
    16.     }
    17.     public static final class id {
    18.         public static final int Adres=0x7f050001;
    19.         public static final int Arama=0x7f050007;
    20.         public static final int Dolum=0x7f050002;
    21.         public static final int Dur=0x7f050006;
    22.         public static final int Ekran=0x7f050008;
    23.         public static final int Git=0x7f050005;
    24.         public static final int Zemin=0x7f050000;
    25.         public static final int geritusu=0x7f050004;
    26.         public static final int ileritusu=0x7f050003;
    27.     }
    28.     public static final class layout {
    29.         public static final int main=0x7f030000;
    30.     }
    31.     public static final class string {
    32.         public static final int app_name=0x7f040001;
    33.         public static final int arama=0x7f040006;
    34.         public static final int dur=0x7f040005;
    35.         public static final int geri=0x7f040003;
    36.         public static final int git=0x7f040004;
    37.         public static final int hello=0x7f040000;
    38.         public static final int ileri=0x7f040002;
    39.     }
    40. }
    41.  
    42.  
    AndroidManifest.xml:
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.HelloWebView2"
    5.     android:versionCode="1"
    6.     android:versionName="1.0" >
    7.  
    8.     <uses-sdk android:minSdkVersion="10" />
    9.     <uses-permission android:name="android.permission.INTERNET" />
    10.     <application
    11.         android:icon="@drawable/ic_launcher"
    12.         android:label="@string/app_name" >
    13.         <activity android:name=".HelloGoogleMaps" android:label="@string/app_name"
    14.      android:theme="@android:style/Theme.NoTitleBar"/>
    15.         <activity
    16.             android:name=".HelloWebView2Activity"
    17.             android:label="@string/app_name" >
    18.             <intent-filter>
    19.                 <action android:name="android.intent.action.MAIN" />
    20.  
    21.                 <category android:name="android.intent.category.LAUNCHER" />
    22.             </intent-filter>
    23.         </activity>
    24.     </application>
    25.  
    26. </manifest>
    27.  
    This is running true.But i take "force close" error in emulator.
     
  3. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    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.
     
  4. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    It has not a logcat report or LintWarnings.
     

    Attached Files:

  5. Lemoncog

    Lemoncog Newbie
    Rank:
    None
    Points:
    36
    Posts:
    26
    Joined:
    Feb 23, 2011

    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.
     
  6. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    What development environment are you using? How are you running your app?

    When does it crash? Immediately on startup? After you do something?
     
  7. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    I Exceptioned.This is Lint Warnings:
    Code (Text):
    1.  
    2. Message:  
    3. This text field does not specify an inputType or a hint.
    4. Missing density variation folders in res: drawable-xhdi                                  
    5.  
    6. File:
    7. main.xml  
    8. Web_Tarayici                                
    9.  
    10. Line:
    11.   9
    12.   1
    13.                                                                                            
    I am using eclipse.Android 2.2. Crashing when immediately on startup.
     
  8. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    Ah sorry.I forgot to give LogCat reports:
    Code (Text):
    1.  
    2. 01-12 06:31:53.984: D/AndroidRuntime(283): Shutting down VM
    3. 01-12 06:31:53.984: W/dalvikvm(283): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    4. 01-12 06:31:54.044: E/AndroidRuntime(283): FATAL EXCEPTION: main
    5. 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
    6. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    7. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    8. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    9. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    10. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.os.Handler.dispatchMessage(Handler.java:99)
    11. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.os.Looper.loop(Looper.java:123)
    12. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    13. 01-12 06:31:54.044: E/AndroidRuntime(283):     at java.lang.reflect.Method.invokeNative(Native Method)
    14. 01-12 06:31:54.044: E/AndroidRuntime(283):     at java.lang.reflect.Method.invoke(Method.java:521)
    15. 01-12 06:31:54.044: E/AndroidRuntime(283):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    16. 01-12 06:31:54.044: E/AndroidRuntime(283):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    17. 01-12 06:31:54.044: E/AndroidRuntime(283):     at dalvik.system.NativeStart.main(Native Method)
    18. 01-12 06:31:54.044: E/AndroidRuntime(283): Caused by: java.lang.ClassCastException: android.text.SpannableStringBuilder
    19. 01-12 06:31:54.044: E/AndroidRuntime(283):     at com.Web_Tarayici.Web_TarayiciActivity.onCreate(Web_TarayiciActivity.java:41)
    20. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    21. 01-12 06:31:54.044: E/AndroidRuntime(283):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    22. 01-12 06:31:54.044: E/AndroidRuntime(283):     ... 11 more
    23.  
     
  9. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    You haven't provided the code for com.Web_Tarayici.Web_TarayiciActivity. What's on line 41 of Web_TarayiciActivity.java?
     
  10. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    I opened alike project in another name Web_TarayiciActivity.And compiled this project.Namely alike codes.
     
  11. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    I don't understand what this means.
     
  12. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    Web_TarayiciActivity project=this project
    this=Web_TarayiciActivity
     
  13. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    In that case, the problematic line is:
    Code (Text):
    1.  
    2. sayfa=(String) AdresCubugu.getText();
    3.  
    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 (Text):
    1.  
    2. sayfa=AdresCubugu.getText().toString();
    3.  

    EDIT: And similarly on line 48.
     
  14. scorpi10

    scorpi10 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    11
    Joined:
    Jan 11, 2012

    Jan 11, 2012
    11
    0
    15
    Yes.It works fine.Thank u for ur helps.This is java's basic rule.But i forgot it:)
     

Share This Page

Loading...