1

私はアンドロイドが初めてです。同じアクティビティで BroadcastReceiver を定義し、AndroidManifest.xml にエントリを入力しても例外が発生します。

public class CheckTicketReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        message = intent.getAction();

        if(message != null) {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
            if(message.equals("100")) {
                intent = new Intent(); 
                intent.setComponent(new ComponentName("com.sec.android.wallet", "com.sec.android.wallet.ui.activity.ticket.ExternalTicketDetailViewActivity")); 
                // Ticket ID (mandatory) 
                intent.putExtra("TICKET_ID", ticketId); 
                // Bounce ID (optional), set as the current system timestamp in milliseconds 
                intent.putExtra("BOUNCE_ID", ""+System.currentTimeMillis()); 
                // RESULT_ACTION (mandatory) 
                intent.putExtra("RESULT_ACTION", "com.sample.partners.action.VIEW_TICKET_RESULT"); 
                startActivity(intent); 
            }
        }
    }
}

AndroidManifest.xml のレシーバー

<receiver android:name=".BrandDetailActivity$CheckTicketReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="com.sec.android.wallet.action.CHECK_TICKET" />
    </intent-filter>
</receiver>

スタックトレース

10-23 00:54:37.148: E/AndroidRuntime(19923): FATAL EXCEPTION: main
10-23 00:54:37.148: E/AndroidRuntime(19923): java.lang.RuntimeException: Unable to instantiate receiver com.passbeemedia.BrandDetailActivity$CheckTicketReceiver: java.lang.InstantiationException: com.passbeemedia.BrandDetailActivity$CheckTicketReceiver
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:1777)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.app.ActivityThread.access$2400(ActivityThread.java:117)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.os.Looper.loop(Looper.java:130)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.app.ActivityThread.main(ActivityThread.java:3687)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at java.lang.reflect.Method.invokeNative(Native Method)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at java.lang.reflect.Method.invoke(Method.java:507)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at dalvik.system.NativeStart.main(Native Method)
10-23 00:54:37.148: E/AndroidRuntime(19923): Caused by: java.lang.InstantiationException: com.passbeemedia.BrandDetailActivity$CheckTicketReceiver
10-23 00:54:37.148: E/AndroidRuntime(19923):    at java.lang.Class.newInstanceImpl(Native Method)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at java.lang.Class.newInstance(Class.java:1409)
10-23 00:54:37.148: E/AndroidRuntime(19923):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:1768)
10-23 00:54:37.148: E/AndroidRuntime(19923):    ... 10 more
4

1 に答える 1

2

クラスを静的にして、問題を解決しました。

ありがとうございます

于 2013-10-22T19:51:09.237 に答える