I cant find how to remove the errors in the code below
package com.example.hellocodelearn;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.example.hellocodelearn.models.Notes;
public class NotesListActivity extends ListActivity
{
private ArrayAdapter NotesItemArrayAdapter ;
private List<Notes> notes = new ArrayList<Notes>() ;
for ( int i = 0; i < 20; i++ )
{
Notes tweet = new Notes();
tweet.setTitle("A nice header for Tweet # " +i);
tweet.setBody("Some random body text for the tweet # " +i);
notes.add(tweet);
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notes_list);
NotesItemArrayAdapter = new NotesAdapter(this, new String[10]);
setListAdapter(NotesItemArrayAdapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
Intent intent = new Intent(this, NotesDetailActivity.class);
startActivity(intent);
}
}
I get errors :
Description Resource Path Location Type
Syntax error on token ",", ; expected NotesListActivity.java /HelloCodeLearn/src/com/example/hellocodelearn line 47 Java Problem
Pleas help.Thanks.
您的类主体中不能有for循环,它必须放在方法内部。
The for
loop should be in a method rather than in the class block
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notes_list);
for (int i = 0; i < 20; i++ ) {
....
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.