当我单击按钮显示错误消息时:不幸的是,学习已经停止了这里的错误
按钮代码:
Button btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1 = new Intent(v.getContext(),Letters.class);
i1.putExtra("Ar", "a5");
startActivity(i1);
}
});
这是 letter.java 代码:
什么是错误以及如何修复它。
package com.example.learn;
import com.example.learn.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.*;
public class Letters extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_letters);
ImageView image = new ImageView(this);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativelayout1);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Bundle extras = getIntent().getExtras();
String Ar_let=extras.getString("Ar");
Toast.makeText(this, Ar_let, Toast.LENGTH_LONG).show();
if(Ar_let=="a1")
{
image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.ar_a);
rl.addView(image, lp);
}
else if(Ar_let=="a2")
{
image = (ImageView) findViewById(R.id.imageView2);
image.setImageResource(R.drawable.ar_b);
rl.addView(image, lp);
}
else if(Ar_let=="a3")
{
image = (ImageView) findViewById(R.id.imageView3);
image.setImageResource(R.drawable.ar_c);
rl.addView(image, lp);
}
else if(Ar_let=="a4")
{
image = (ImageView) findViewById(R.id.imageView4);
image.setImageResource(R.drawable.ar4);
rl.addView(image, lp);
}
else if(Ar_let=="a5")
{
image = (ImageView) findViewById(R.id.imageView5);
image.setImageResource(R.drawable.ar5);
rl.addView(image, lp);
}
else
{
image = (ImageView) findViewById(R.id.imageView5);
image.setImageResource(R.drawable.ar5);
rl.addView(image, lp);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.letters, menu);
return true;
}
}
请问是什么错误??!!
我删除 Letters.java 并再次添加,但同样的事情