语法错误{预期

时间:2012-09-18 01:42:06

标签: android

第28行和该行显示有两个错误,可能是某些人为什么会收到这些错误

package com.xcxcxc;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.UserDictionary;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;


public class UserDict extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audiolistmain);
}

SimpleCursorAdapter adapter;
ListView audiolist = (ListView) findViewById(R.id.audioList);


String[] mProjection =
{
    UserDictionary.Words._ID,    
    UserDictionary.Words.WORD,   
    UserDictionary.Words.LOCALE  
};

String mSelectionClause = null;
String[] mSelectionArgs = {""};
static final String[] DBFIELDS= {UserDictionary.Words.WORD,     UserDictionary.Words.LOCALE};
static final int[] LISTFIELDS = { R.id.dictWord,R.id.locale};

String mSearchString = "m";  //syntax error on token ";" { expected after this token
if (TextUtils.isEmpty(mSearchString)) {
mSelectionClause = null;
mSelectionArgs[0] = "";

} else {
    mSelectionClause = UserDictionary.Words.WORD + " = ?";
    mSelectionArgs[0] = mSearchString;

}   

Cursor mCursor = getContentResolver().query(
    UserDictionary.Words.CONTENT_URI,  
mProjection,                       
mSelectionClause,                  
mSelectionArgs,                    
null);

if (null == mCursor) {
Log.e("Cursor returned null, query could not be performed","");
} else if (mCursor.getCount() < 1) {
Toast.makeText(this, "nowords"+mSearchString+"found",     Toast.LENGTH_LONG).show();
} else {
int[] mWordListItems = { R.id.dictWord, R.id.locale};
String[] mWordListColumns =
{
UserDictionary.Words.WORD,   
UserDictionary.Words.LOCALE  
};

SimpleCursorAdapter mCursorAdapter = new SimpleCursorAdapter(
getApplicationContext(),               
R.layout.row,                   
mCursor,                            
DBFIELDS,                      
LISTFIELDS); 


audiolist.setAdapter(mCursorAdapter);

}   // syntax error insert } to complete class body       

4 个答案:

答案 0 :(得分:3)

紧跟在您显示为标记错误的行之后的行是应该在方法内的代码,但不是。我猜你不想在这一行之后关闭onCreate

setContentView(R.layout.audiolistmain);

并且您在此处列出的所有代码都应该是该方法的一部分。只需删除下一行的右括号},然后在文件末尾添加两个右括号,它就应该匹配。

答案 1 :(得分:2)

要解决第二个问题,您需要在文件末尾关闭“}”以完成类主体。

答案 2 :(得分:0)

如果你仍然没有得到@Xono所说的话

删除{of this

    package com.xcxcxc;
    import android.app.Activity;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.provider.UserDictionary;
    import android.text.TextUtils;
    import android.util.Log;
    import android.widget.ListView;
    import android.widget.SimpleCursorAdapter;
    import android.widget.Toast;


    public class UserDict extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.audiolistmain);
    }   <--------------- THIS ONE
    ^
    |
    |
    |
    |
    |
    |
    |
 THIS ONE

把它放在最底层......

修改

还要添加另一个{关闭课程。

答案 3 :(得分:0)

package com.xcxcxc;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.UserDictionary;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;


public class UserDict extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.audiolistmain);
    // "{" ====>> Removed

    SimpleCursorAdapter adapter;
    ListView audiolist = (ListView) findViewById(R.id.audioList);


    String[] mProjection =
    {
        UserDictionary.Words._ID,    
        UserDictionary.Words.WORD,   
        UserDictionary.Words.LOCALE  
    };

    String mSelectionClause = null;
    String[] mSelectionArgs = {""};
    static final String[] DBFIELDS= {UserDictionary.Words.WORD,     UserDictionary.Words.LOCALE};
    static final int[] LISTFIELDS = { R.id.dictWord,R.id.locale};

    String mSearchString = "m";  //syntax error on token ";" { expected after this token
    if (TextUtils.isEmpty(mSearchString)) {
        mSelectionClause = null;
        mSelectionArgs[0] = "";

    } else {
        mSelectionClause = UserDictionary.Words.WORD + " = ?";
        mSelectionArgs[0] = mSearchString;
    }   

    Cursor mCursor = getContentResolver().query( UserDictionary.Words.CONTENT_URI,  
                mProjection,                       
                mSelectionClause,                  
                mSelectionArgs,                    
                null);

    if (null == mCursor) {
        Log.e("Cursor returned null, query could not be performed","");
    } else if (mCursor.getCount() < 1) {
        Toast.makeText(this, "nowords"+mSearchString+"found",     Toast.LENGTH_LONG).show();
    } else {
        int[] mWordListItems = { R.id.dictWord, R.id.locale};
        String[] mWordListColumns =
        {
            UserDictionary.Words.WORD,   
            UserDictionary.Words.LOCALE  
        };

        SimpleCursorAdapter mCursorAdapter = new SimpleCursorAdapter(
                                        getApplicationContext(),               
                                        R.layout.row,                   
                                        mCursor,                            
                                        DBFIELDS,                      
                                        LISTFIELDS); 


        audiolist.setAdapter(mCursorAdapter);

    } 
}   //===========> "}" added
}   //===========> "}" added