0

ダイアログからアクティビティに移行できないようです。理由を理解できる人がいるかどうか疑問に思いました。

これは、このプロジェクトを提出する前に修正する必要がある最後のバグです。

パッケージcom.mkyong.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AppActivity extends Activity {

final Context context = this;
private Button button;

public void onCreate(Bundle savedInstanceState) {

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

    button = (Button) findViewById(R.id.button1);

    // add button listener
    button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);

        // set title
        alertDialogBuilder.setTitle("Settings Menu");

        // set dialog message
        alertDialogBuilder
            .setMessage("Link or Delete?")
            .setCancelable(false)
            .setPositiveButton("Link",new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int id) {
            //start new activity

            Intent intentApp2Activity = new Intent(AppActivity.this, App2Activity.class);
            startActivity(intentApp2Activity);

            // if this button is clicked, close
            // current activity
            AppActivity.this.finish();
        }
      })
            .setNegativeButton("Delete",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }
    });
}

}

03-02 08:16:32.219: E/AndroidRuntime(5484): FATAL EXCEPTION: main
03-02 08:16:32.219: E/AndroidRuntime(5484): java.lang.Error: Unresolved compilation problems: 
03-02 08:16:32.219: E/AndroidRuntime(5484): Intent cannot be resolved to a type
03-02 08:16:32.219: E/AndroidRuntime(5484): Intent cannot be resolved to a type
03-02 08:16:32.219: E/AndroidRuntime(5484): at com.mkyong.android.AppActivity$1$1.onClick(AppActivity.java:44)
03-02 08:16:32.219: E/AndroidRuntime(5484): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
03-02 08:16:32.219: E/AndroidRuntime(5484): at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 08:16:32.219: E/AndroidRuntime(5484): at android.os.Looper.loop(Looper.java:137)
03-02 08:16:32.219: E/AndroidRuntime(5484): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-02 08:16:32.219: E/AndroidRuntime(5484): at java.lang.reflect.Method.invokeNative(Native Method)
03-02 08:16:32.219: E/AndroidRuntime(5484): at java.lang.reflect.Method.invoke(Method.java:511)
03-02 08:16:32.219: E/AndroidRuntime(5484): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-02 08:16:32.219: E/AndroidRuntime(5484): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-02 08:16:32.219: E/AndroidRuntime(5484): at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

0

android.content.Intent をインポートしたことを確認し、プロジェクトを消去して再構築します。

これは Android の不安定な部分です。例外が示唆するように、コンパイル時エラーを生成する未解決のコンパイル時問題があります。ADT または Eclipse (Eclipse を使用していると仮定します) のバグのようなにおいがします。

于 2013-03-02T08:30:38.213 に答える