1、The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
点击按钮,进入另一个activity,问题代码如下
Button btn = (Button)findViewById(R.id.btnMe);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(this, ButtonStudyActivity.class);
startActivity(intent);
}});
Intent intent = new Intent(Activityheihei.this, ButtonStudyActivity.class);解决方案二:
final Intent intent = new Intent(Activityheihei.this, ButtonStudyActivity.class);
Button btn = (Button)findViewById(R.id.btnMe);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(intent);
}});
解决方案三:
final Intent intent = new Intent(this, ButtonStudyActivity.class);
Button btn = (Button)findViewById(R.id.btnMe);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(intent);
}});
2、ActivityManager: Warning: Activity not started, its current task has been brought to the front
Eclipse中,Project->Clean...,然后选中项目,clean一下即可。
3、E/AndroidRuntime(338): java.lang.IllegalStateException: Could not find a methodonClickBtnManifest(View) in the activity class cn.edu.pku.Activityheihei for onClick handler on view class android.widget.Button with id 'btnmanifest'
想给Button中加入点击事件
<Button android:id="@+id/btnmanifest" ... ... android:onClick="onClickBtnManifest" />
Activity中实现如下
private void onClickBtnManifest() { Toast.makeText(Activityheihei.this, "button manifest", Toast.LENGTH_SHORT).show(); }该函数需要加入参数View v,之后还是这个错误。private改为public即可。
public void onClickBtnManifest(View v) {
Toast.makeText(Activityheihei.this, "button manifest", Toast.LENGTH_SHORT).show();
}
使用高版本的SDK后再导入以前用低版本的project时,会遇到一些兼容性的问题。
需要将project.properties中的target=android-5改为target=android-7就好了。
但要注意,也要同步将AndroidManifest.xml中的<uses-sdk android:minSdkVersion="5" />改为<uses-sdk android:minSdkVersion="7" />,否则编译中会警告提示使用的版本过低。
参考http://blog.sina.com.cn/s/blog_64edd5040100nu0d.html