0
我在Android Studio 2.0中出现错误“预期的类型ID错误资源”。代码实际上很简单。我正在尝试学习意图,但在setContentView方法中出现错误。你能检查一下吗?预期的类型id错误资源 - Android
//代码从这里开始
package com.example.oksijen02.sorunmuvar; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { private static final int REQUEST_CODE=10; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //following line getting error of "expected resource of type id.." setContentView(findViewById(R.layout.activity_main)); } // here button action to define an intent and its extra value public void onClick(View view){ EditText text= (EditText) findViewById(R.id.inputforintent); String value = text.getText().toString(); //Define intent Intent intent = new Intent(this,ResultActivity.class); //add Edit Text value to send next activity via intent intent.putExtra("senttext",value); } }
//我们有MainActivity XML这里
//Edit Text in main activity <EditText android:id="@+id/inputforintent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="60dip" android:text="FirstActivity" android:textSize="20sp" /> //here we have button to pass other page which its code unwritten here <Button android:id="@+id/startIntent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/inputforintent" android:layout_below="@+id/inputforintent" android:onClick="onClick" android:text="Calling an intent" />
感谢Nolly的答案 – luckystones