其实我读的答案,但我在做什么now.I正在使用Eclipse处于迷茫的状态,我也得到在lines--错误Android的错误:R 1不能被解析为一个变量
setContentView(R.layout.activity_main);
Clickhere=(Button)findViewById(R.id.button1);
getMenuInflater().inflate(R.menu.main,menu);
这里是下面的代码: -
package com.example.vaish;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button Clickhere;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Clickhere=(Button)findViewById(R.id.button1);
Clickhere.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i=new Intent(getApplicationContext(),MainActivity1.class);
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main,menu);
return true;
}
}
XML文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/happy" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Clickhere" />
</RelativeLayout>
please help!!!
我需要清除错误。
如果在资源文件中的错误,这个错误会显示。请先检查您的资源文件。 –
太旧的问题 –
检查是否有任何xml文件中的错误 – Raghavendra