我正在关注Sams 24hr编程书,但对于我的生活似乎无法解决我在第2小时的问题。
我正在尝试创建一个简单的按钮来启动第二个活动,并在第二个活动中更改TextArea。
这是我的第二个活动的代码。我得到"表达期待"在Intent in" Intent = getIntent();"和" getStringExtra"非静态方法不能从静态内容中引用。
我的代码看起来和我的书一样:S
package co.jamesbrown.hour2app;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class Second extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent= getIntent();
String message = Intent.getStringExtra("co.jamesbrown.MESSAGE");
TextView messageTextView = (TextView) findViewById(R.id.message);
messageTextView.setText(message);
}
}

提前致谢
詹姆斯
答案 0 :(得分:2)
将其更正为
Intent intent= getIntent();
String message = intent.getStringExtra("co.jamesbrown.MESSAGE");
答案 1 :(得分:1)
false
这不是#include <stdio.h>
int main()
{
int i;
char surname[30];
char name[30], matricno[10];
int A, B, C;
FILE *file, *file1;
/* Open an existing file */
file = fopen("Broadsheett.txt","r");
if(file == NULL){
printf("Error: Unable to open a file");
}
file1 = fopen("newbroadsheet.txt", "w");
fprintf(file1, "University of Nairaland\n");
fprintf(file1, "Department of Programming\n");
fprintf(file1, "================================\n");
while (!feof(file)) {
fscanf(file, "%s\t%s\t%d\t%d\n", &name, &matricno, &A, &B);
fprintf(file1, "%s\t%s\t%d\t%d\n", name, matricno, A, B);
}
}
表达。您需要在Intent= getIntent();
中声明变量时给出一个名称,如下所示:
Java
然后你可以这样做:
Java
获取通过Intent yourIntent = getIntent();
传递的String message = yourIntent.getStringExtra("co.jamesbrown.MESSAGE");
值。
答案 2 :(得分:0)
除了给出的答案,你也可以用另一种方式写出来
myArray = [
{
name: Person 1
type: alpha
},
{
name: Person 2
type: beta
},
{
name: Person 3
type: gamma
},
{
name: Person 4
type: beta
},
{
name: Person 5
type: gamma
},
};