質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

2回答

2574閲覧

androidでnotificationが起動しません

tsunenori

総合スコア9

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2015/01/21 10:47

androidアプリ開発を勉強し始めたばかりです
まず、notificationを使いたいと思い、解説本からコピペして実行すると、Botton時点で「問題が発生したため~」と強制終了します。
どうしたら正常にnotificationが表示されるか教えてください。

logcatのエラーっぽい部分には以下の様に表示されました
E/AndroidRuntime(11099): java.lang.IllegalStateException: Could not find a method do Action(View) in the activity class com.example.ryosyou.MainActivity for onClick handler on view class android.widget.Button with id 'button1'

mainActivityの加筆部分
public void doAction(View view){
EditText edit1=(EditText)this.findViewById(R.id.editText1);
Editable s = edit1.getText();
Intent intent=new Intent(this,com.example.ryosyou.MainActivity.class);
PendingIntent pending=PendingIntent.getActivity(this, 1, intent,PendingIntent.FLAG_CANCEL_CURRENT);
Notification notify=new Notification();
notify.flags=Notification.FLAG_AUTO_CANCEL;
notify.icon=R.drawable.ic_launcher;
notify.tickerText="!Hello!";
notify.setLatestEventInfo(this, "Hello Info", "message:"+s , pending);
NotificationManager manager=(NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE);
manager.notify(1, notify);

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

public class MainActivity extends Activity {

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnNext1 = (Button) findViewById(R.id.button_01); btnNext1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){ doAction(v); } });

}

public void doAction(View view){ EditText edit1=(EditText)this.findViewById(R.id.editText1); Editable s = edit1.getText(); Intent intent=new Intent(this,com.example.test01.MainActivity.class); PendingIntent pending=PendingIntent.getActivity(this, 1, intent,PendingIntent.FLAG_CANCEL_CURRENT); Notification notify=new Notification(); notify.flags=Notification.FLAG_AUTO_CANCEL; notify.icon=R.drawable.ic_launcher; notify.tickerText="!Hello!"; notify.setLatestEventInfo(this, "Hello Info", "message:"+s , pending); NotificationManager manager=(NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE); manager.notify(1, notify); }

}

当方環境では動きました。
加筆部分ではなく、それ以外の部分に問題がありそうです。

投稿2015/01/26 05:52

MiyukiAizawa

総合スコア41

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

java.lang.IllegalStateException: ~ Could not find a method do Action
上記のdoスペースAction部分が気になるのですが、
xml部分も含めてMainActivity.class見せてもらうことができるでしょうか。

http://androidapp.blog.jp/archives/1918584.html

投稿2015/01/21 12:14

usop

総合スコア64

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問