0

在我点击选项菜单上的 NearBy 按钮后,我很难理解为什么我的代码没有进入 try 语句。它进入黑屏,但 IN NEAR CASE 字符串未显示在 Eclipse 中的 logcat 或 Android 手机上的 aLogCat 的输出中?我究竟做错了什么?

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ProfileActivity extends Activity {

private static final int NEAR = Menu.FIRST;

public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, NEAR, 0, "NearBy").setIcon(android.R.drawable.ic_menu_info_details);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

   switch (item.getItemId()) {
   case NEAR:
       try {
           Log.e(LOG_TAG,"IN NEAR CASE");
               Intent myIntent = new Intent(ProfileActivity.this,
                      AndroidClient.class);
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
            Toast.makeText(this, "Value Age is not correct", Toast.LENGTH_LONG).show();
        } catch (NullPointerException npe) {
            npe.printStackTrace();
            Toast.makeText(this, "Error", Toast.LENGTH_LONG).show();
        }

        break;
    }

    return true;
}
}
4

1 回答 1

0

您希望您的应用程序做什么?您发布的代码编译得很好。

你想启动 AndroidClient 吗?添加这个:

Intent myIntent = new Intent(ProfileActivity.this, AndroidClient.class);
startActivity(myIntent);

请注意,您没有 onCreate() 方法,因此屏幕将始终为空白,除非您使用 setContentView() 加载布局。(我猜这是您的应用程序的缩短版本,但我想彻底。)

于 2012-08-09T00:40:50.333 回答