力量关闭,我不知道为什么

时间:2013-04-26 03:17:50

标签: java android

目前我正在开发Android应用程序,但它会继续强行关闭。我将发布我已完成的代码。 testproject gui只是一个简单的按钮。当我点击按钮时,它应该转到相机类。然而,它强行关闭。我自己运行相机,它的工作原理。 :/

Testproject类:

  package com.example.testproject;

  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;

  public class Testproject extends Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

Button bc;

bc = (Button)findViewById(R.id.btncamera); 

bc.setOnClickListener(new OnClickListener(){
    public void onClick(View v){
        Intent intent = new Intent(Testproject.this, Camera.class);
        startActivity(intent);
    }
});

}

    }

相机类:

    package com.example.testproject;

    import java.io.IOException;

    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageButton;
    import android.widget.ImageView;

    public class Camera extends Activity implements View.OnClickListener     {

ImageButton ib;
Button b;
ImageView iv;
Intent i;
final static int cameraResults = 0;
Bitmap bmp;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.camera);
    initialize();
}

public void initialize(){
    iv = (ImageView) findViewById (R.id.ivReturnedPic);
    ib = (ImageButton) findViewById (R.id.ibTakePic);
    b = (Button) findViewById (R.id.bSetWall);
    b.setOnClickListener(this);
    ib.setOnClickListener(this);

}

    @Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    switch (v.getId()){
    case R.id.bSetWall:
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         break;

    case R.id.ibTakePic:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i,cameraResults);
        break;
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap)extras.get("data");
        iv.setImageBitmap(bmp);

    }
}

    }

2 个答案:

答案 0 :(得分:0)

确保您在manifest.xml文件中拥有所有适当的权限。如果您使用相机,则需要:

<uses-permission android:name="android.permission.CAMERA" />

答案 1 :(得分:0)

确保您已在camera

中添加了manifest.xml个活动