-1

Android プログラミング クラスの場合、QuickAction アクティビティを実装しようとしていますが、プログラムにロードできません。これは、ロード時に失敗していると思われるコードです。

    import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity
{

    @Override

    protected void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //show on iBtn1
        ImageButton iBtn1 = (ImageButton) this.findViewById(R.id.iBtn1);
        iBtn1.setOnClickListener(new View.OnClickListener()
        {



            @Override
            public void onClick(View v)
            {

                startActivity(new Intent(getApplicationContext(),
                        QuickActionBar.class));
            }

        });


        final QuickActionIcons edit = new QuickActionIcons();;

        edit.setTitle("Edit");
        edit.setIcon(getResources().getDrawable(R.drawable.edit));

        edit.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                Toast.makeText(MainActivity.this,"Edit Contact",Toast.LENGTH_SHORT).show();
            }

        });

        final QuickActionIcons call = new QuickActionIcons();;

        call.setTitle("Call");
        call.setIcon(getResources().getDrawable(R.drawable.call));

        call.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                Toast.makeText(MainActivity.this,"Call Contact",Toast.LENGTH_SHORT).show();
            }

        });

        final QuickActionIcons call3 = new QuickActionIcons();;

        call3.setTitle("Call3");
        call3.setIcon(getResources().getDrawable(R.drawable.call));

        call3.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                // Toast.makeText(QuickActionSampleAppActivity.this,"Call Contact",Toast.LENGTH_SHORT).show();
            }

        });

        final QuickActionIcons call1 = new QuickActionIcons();;

        call1.setTitle("Call 1");      
        call1.setIcon(getResources().getDrawable(R.drawable.call));

        call1.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                // Toast.makeText(QuickActionSampleAppActivity.this,"Call Contact",Toast.LENGTH_SHORT).show();
            }

        });

        final QuickActionIcons call2 = new QuickActionIcons();;

        call2.setTitle("Call 2");       
        call2.setIcon(getResources().getDrawable(R.drawable.call));

        call2.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                // Toast.makeText(QuickActionSampleAppActivity.this,"Call Contact",Toast.LENGTH_SHORT).show();
            }

        });

        final QuickActionIcons send_data = new QuickActionIcons();;

        send_data.setTitle("Send Data");      
        send_data.setIcon(getResources().getDrawable(R.drawable.bluetooth));

        send_data.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                //  Toast.makeText(QuickActionSampleAppActivity.this,"Start Transfer of Data",Toast.LENGTH_SHORT).show();
            }

        });

        QuickActionBar qab = new QuickActionBar(iBtn1);
        qab.addItem(edit);
        qab.addItem(call);
        qab.addItem(send_data);
        qab.addItem(call1);
        qab.addItem(call2);
        qab.addItem(call3);
        qab.setAnimationStyle(QuickActionBar.GROW_FROM_LEFT);
        qab.show();


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

これが私のLogCatです

    01-30 17:16:39.650: E/Trace(810): error opening trace file: No such file or directory (2)
    01-30 17:16:39.650: W/Trace(810): Unexpected value from nativeGetEnabledTags: 0
    01-30 17:16:39.650: W/Trace(810): Unexpected value from nativeGetEnabledTags: 0
    01-30 17:16:39.650: W/Trace(810): Unexpected value from nativeGetEnabledTags: 0
    01-30 17:16:40.038: W/Trace(810): Unexpected value from nativeGetEnabledTags: 0
    01-30 17:16:40.038: W/Trace(810): Unexpected value from nativeGetEnabledTags: 0
    01-30 17:16:41.618: D/dalvikvm(810): GC_CONCURRENT freed 67K, 7% free 2811K/3000K, paused 18ms+5ms, total 90ms
    01-30 17:16:41.618: D/dalvikvm(810): WAIT_FOR_CONCURRENT_GC blocked 56ms
    01-30 17:16:41.638: I/dalvikvm-heap(810): Grow heap (frag case) to 3.933MB for 1127536-byte allocation
    01-30 17:16:41.718: D/dalvikvm(810): GC_FOR_ALLOC freed 3K, 5% free 3909K/4104K, paused 74ms, total 75ms
    01-30 17:16:41.838: D/dalvikvm(810): GC_CONCURRENT freed <1K, 5% free 4098K/4296K, paused 9ms+20ms, total 124ms
    01-30 17:16:42.058: D/AndroidRuntime(810): Shutting down VM
    01-30 17:16:42.058: W/dalvikvm(810): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
    01-30 17:16:42.108: E/AndroidRuntime(810): FATAL EXCEPTION: main
    01-30 17:16:42.108: E/AndroidRuntime(810): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.rasmussen.mobile/edu.rasmussen.mobile.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.os.Handler.dispatchMessage(Handler.java:99)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.os.Looper.loop(Looper.java:137)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.ActivityThread.main(ActivityThread.java:5039)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at java.lang.reflect.Method.invokeNative(Native Method)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at java.lang.reflect.Method.invoke(Method.java:511)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at dalvik.system.NativeStart.main(Native Method)
    01-30 17:16:42.108: E/AndroidRuntime(810): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.widget.PopupWindow.invokePopup(PopupWindow.java:993)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.widget.PopupWindow.showAtLocation(PopupWindow.java:847)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.widget.PopupWindow.showAtLocation(PopupWindow.java:811)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at edu.rasmussen.mobile.QuickActionBar.show(QuickActionBar.java:120)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at edu.rasmussen.mobile.MainActivity.onCreate(MainActivity.java:141)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.Activity.performCreate(Activity.java:5104)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    01-30 17:16:42.108: E/AndroidRuntime(810):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    01-30 17:16:42.108: E/AndroidRuntime(810):  ... 11 more

Here are the Console
[2013-01-30 11:13:08 - GeoTag] ------------------------------
[2013-01-30 11:13:08 - GeoTag] Android Launch!
[2013-01-30 11:13:08 - GeoTag] adb is running normally.
[2013-01-30 11:13:08 - GeoTag] Performing edu.rasmussen.mobile.MainActivity activity launch
[2013-01-30 11:13:08 - GeoTag] Automatic Target Mode: launching new emulator with compatible AVD 'Galaxy'
[2013-01-30 11:13:08 - GeoTag] Launching a new emulator with Virtual Device 'Galaxy'
[2013-01-30 11:13:13 - GeoTag] New emulator found: emulator-5554
[2013-01-30 11:13:13 - GeoTag] Waiting for HOME ('android.process.acore') to be launched...
[2013-01-30 11:14:50 - GeoTag] HOME is up on device 'emulator-5554'
[2013-01-30 11:14:50 - GeoTag] Uploading GeoTag.apk onto device 'emulator-5554'
[2013-01-30 11:14:50 - GeoTag] Installing GeoTag.apk...
[2013-01-30 11:16:28 - GeoTag] Success!
[2013-01-30 11:16:28 - GeoTag] Starting activity edu.rasmussen.mobile.MainActivity on device emulator-5554
[2013-01-30 11:16:31 - GeoTag] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=edu.rasmussen.mobile/.MainActivity }

スタックトレース

GeoTag [Android Application]    
    DalvikVM[localhost:8789]    
        Thread [<1> main] (Running) 
        Thread [<10> Binder_2] (Running)    
        Thread [<9> Binder_1] (Running) 
4

1 に答える 1

1

例外メッセージ:

ウィンドウを追加できません -- トークン null は無効です。あなたの活動は進んでいますか?

アクティビティがこれを処理する準備ができていないときに、アクティビティの上にウィンドウを追加しようとしています (アクティビティのウィンドウはまだ表示されていません)。これに対処するには多くの方法があります。解決策の 1 つは、ポストランナブルを使用することである可能性があるため、アクションが遅れます。

view.post(new Runnable() {
   public void run() {
      // show your quick action here
   }
});
于 2013-01-30T18:34:25.620 に答える