我是Android上的全新用户。我试图设置菜单按钮并遇到了这个问题。我在这个论坛上检查了一下,发现这意味着未定义,但是无法弄清代码中的哪个未定义。请帮忙!任何建议将不胜感激。

顺便说一句,如果我单独运行,Camera_SettingActivity.java可以正常工作。

public class VideoViewActivity extends Activity {

    protected int my_num = 2280;
    protected Intent intent_camera;

    /** Called when the activity is first created. */
            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.layout.menu, menu);
                return true;
            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {

                intent_camera = new Intent();

                switch (item.getItemId()) {

                    case R.id.camera:
                        intent_camera.setClass(VideoViewActivity.this, Camera_SettingActivity.class);
                        startActivityForResult(intent_camera, my_num);
                        break;

                }
                return true;
            }

}



public class Camera_SettingActivity extends Activity {


protected int my_num = 1228;
private Bundle bundle;

public static String url = "rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmXovF6e-Rf-BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
private VideoView videoView1 = null;
private Context ctx = null;
private ProgressBar prog1 = null;

protected String str_IP;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_camera_layout);

    bundle = this.getIntent().getExtras();

    str_IP = bundle.getString("editIP");

    Button test1 = (Button) findViewById(R.id.button_test1);

    test1.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {

            prog1 = (ProgressBar)findViewById(R.id.progressBar1);
                    videoView1  = (VideoView) findViewById(R.id.videoView1);
                    Uri video   = Uri.parse(url);

                    videoView1.setVideoURI(video);

                    videoView1.setOnErrorListener(new OnErrorListener() {

                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            // TODO Auto-generated method stub
                            Toast.makeText(ctx, "Error occured", 500).show();
                            return false;
                        }
                    });

                    videoView1.setOnPreparedListener(new OnPreparedListener() {

                        public void onPrepared(MediaPlayer arg0) {
                            prog1.setVisibility(View.GONE);
                            videoView1.start();
                        }
                    });
             }

    });
}

 @Override
 protected void onDestroy() {
     try{
         videoView1.stopPlayback();
     }catch(Exception e){
         //
     }
     super.onDestroy();
 }


}

最佳答案

每个活动都应具有onCreate()方法。您的代码丢失了它。这可能导致错误。在方法内添加onCreate()和setContentView()。

09-30 23:02