0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EditTextのバグに対処した話

0
Posted at

目的

ドットインストールの勉強中に出たエラーの処理。

内容

ドットインストール
「Androidでウェブブラウザを作ろう」の中の
「#08 任意のサイトを表示してみよう」の一部分

MainActivty.java
   public void clearUrl(View view) {
        urlText.setText("");
    }
activty_mail.xml
   <EditText
    ...
    android:onClick="clearUrl"
    ...

エラー内容

EditTextをタップするとアプリが落ちる

Could not find a method clearUrl(View) in the activity class

エラーはclearUrlというメソッドがないという内容

やったこと

エラーを見て始めはclearUrlのタイプミスかと思いましたが、全部をコピペしても解消せず。
SDK、BuildToolsのversionを下げても解消せず。

解決方法

調べたら恐らく同じサイトで同じ場所でエラーが出ている方がいました。

androidのactivity_mainでEditTextにonClickを設定するとエラーが起きる
http://ja.stackoverflow.com/questions/10545/android%E3%81%AEactivity-main%E3%81%A7edittext%E3%81%ABonclick%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%E3%81%A8%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E8%B5%B7%E3%81%8D%E3%82%8B

バグのようなので最終的に
Buttonを新しく作り、そのButtonにonClickを設定しました。

      <Button
          android:text="Clear"
          android:onClick="clearUrl"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />

感想

エラーが出るのは全て自分が悪いはずだと思っていましたが、こういう事もあるんですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?