android程序不按正确执行顺序

lenovoliulin 2012-05-25 12:58:43
我最近写了一段代码,两个Activity,第一个Activity向第二个Activity传一张图片的位置信息(第二个Activity要用第一张图片的信息),第二个Activity部分内容为
class Image{
public Bitmap image;
public int imlen=0;//图像总像素数
public int width;//图像像素矩阵宽
public int height;//图像像素高
public int[] pixel;
}
public class second extends Activity{
/** Called when the activity is first created. */
private ImageButton btn1;//打开文件
private EditText edt3;//显示第二幅图片位置
private ImageButton btn3;//Embedded
public ImageButton btn4;//extract
private ImageButton btn5;//save
private EditText edt;//password
private EditText edt1;//message
private ImageView img1;
public ProgressBar bar;
public Random random = new Random();
public String key = null;
static int[] epixel= null;
public int p=0;//进度条提示
static int b=0;
public Image spic = new Image();
public Image fpic = new Image();//也许错
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
findview();
btn1.setOnClickListener(new MyButtonListener());//打开文件,寻找图片
setImg();
String location = intent.getStringExtra("location");
BitmapFactory.Options options = new BitmapFactory.Options();
if(options != null && location != null)
{
options.inSampleSize = 2;
fpic.image = BitmapFactory.decodeFile(location, options);//get first image
if(fpic.image != null)
{
fpic.image = fpic.image.copy(Bitmap.Config.ARGB_8888, true);
fpic.imlen = (int) fpic.image.getHeight()*fpic.image.getWidth();
fpic.pixel = new int[fpic.imlen];
fpic.image.getPixels(fpic.pixel,0,fpic.image.getWidth(),0,0,fpic.image.getWidth(),fpic.image.getHeight());
btn3.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {//TODO Auto-generated method stub
if(b==0)
Toast.makeText(second.this,"请先从图库中选择图片或者拍照", Toast.LENGTH_SHORT).show();
else
if(edt.getText().toString().length()==0)
Toast.makeText(second.this,"请先输入要密钥", Toast.LENGTH_SHORT).show();
if(edt1.getText().toString().length()==0)
Toast.makeText(second.this,"请先输入要嵌入的内容", Toast.LENGTH_SHORT).show();
else{
try {
key = edt.getText().toString();
byte[] message = edt1.getText().toString().getBytes("ASCII");//嵌入信息(Byte形式)
int[] embed = new int[message.length*8];
embed= match(message,fpic.pixel);//得到匹配序列
String slocation = edt3.getText().toString();
BitmapFactory.Options options = new BitmapFactory.Options();
if(options != null && slocation != null)
{
options.inSampleSize = 2;
spic.image = BitmapFactory.decodeFile(slocation, options);//get first image
if(spic.image != null)
{
spic.image = spic.image.copy(Bitmap.Config.ARGB_8888, true);
spic.imlen = (int) spic.image.getHeight()*spic.image.getWidth();
spic.pixel = new int[spic.imlen];
spic.image.getPixels(spic.pixel,0,spic.image.getWidth(),0,0,spic.image.getWidth(),spic.image.getHeight());
}
}
spic.height = spic.image.getHeight();
spic.pixel = embeded(spic.pixel,embed,key);//嵌入匹配序列
edt.setText("");//将Password置空
edt1.setText("");//将嵌入信息置空
b=2;
}

catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});

可是,当我点击btn3时,程序没有任何反应,程序也不报错。谁能帮我看看。急。。
...全文
360 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lenovoliulin 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
不介意的话 可以把代码法我看看 -_-
[/Quote]
可以把邮箱给我吗?
yhx810971230 2012-05-25
  • 打赏
  • 举报
回复
不介意的话 可以把代码法我看看 -_-
yhx810971230 2012-05-25
  • 打赏
  • 举报
回复
是照片显示不了吗,是不是你的sd卡权限没设置呢
lenovoliulin 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

if(options != null && location != null)
{
后面加上
Toast.makeText(second.this,"有执行噢", Toast.LENGTH_SHORT).show();

有显示的话说明有执行,无的话就要查options和location
[/Quote]
有执行的。我断点设置也是可以执行的,但错误不知道出在哪里了。真是急死人了。大侠,介意留个邮箱,我把代码发给你看看吗?(我也觉得要求有点过分,可这个问题不解决我后面的工作就没法做了)
AMinfo 2012-05-25
  • 打赏
  • 举报
回复

if(options != null && location != null)
{
后面加上
Toast.makeText(second.this,"有执行噢", Toast.LENGTH_SHORT).show();

有显示的话说明有执行,无的话就要查options和location
lenovoliulin 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
说错,能编译过去,但是安装时会报错。建议加点打印,调试一下看看卡在哪个地方。
[/Quote]
能给点加打印的资料吗?我是新手,附近也没有会这个的
lenovoliulin 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
你程序中所有的btn1、btn2....btn5都没有初始化
[/Quote]
public void findview(){
btn1 = (ImageButton) findViewById(R.id.btn1);
edt3 = (EditText) findViewById(R.id.edt3);
btn3 = (ImageButton) findViewById(R.id.btn3);
btn4 = (ImageButton) findViewById(R.id.btn4);
btn5 = (ImageButton) findViewById(R.id.btn5);
edt = (EditText) findViewById(R.id.edt0);
edt1 =(EditText) findViewById(R.id.edt1);
img1 = (ImageView) findViewById(R.id.img1);
bar = (ProgressBar)findViewById(R.id.firstBar);
}有初始化的,就是不行啊。还有可能哪里出错吗
Rayleigh 2012-05-25
  • 打赏
  • 举报
回复
说错,能编译过去,但是安装时会报错。建议加点打印,调试一下看看卡在哪个地方。
Rayleigh 2012-05-25
  • 打赏
  • 举报
回复
应该不是button没有初始化的问题,没初始化更本就编译不过去,猜测findview();

是用来初始化这些button的。
AMinfo 2012-05-25
  • 打赏
  • 举报
回复
你程序中所有的btn1、btn2....btn5都没有初始化
AMinfo 2012-05-25
  • 打赏
  • 举报
回复
btn3 根本没有初始对像啊?

80,493

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧