2016-03-01 62 views
-1
public class MainActivity extends AppCompatActivity { 
     private TaskDBHelper helper; 
     private ListAdapter listAdapter; 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 

      private void updateUI(){ 
       helper = new TaskDBHelper(MainActivity.this); 
       SQLiteDatabase sqlDB = helper.getReadableDatabase(); 
       Cursor cursor = sqlDB.query(TaskContract.TABLE, 
         new String[]{TaskContract.Columns._ID, TaskContract.Columns.TASK}, 
         null, null, null, null, null); 

       listAdapter = new SimpleCursorAdapter(
         this, 
         R.layout.task_view, 
         cursor, 
         new String[]{TaskContract.Columns.TASK}, 
         new int[]{R.id.taskTextView}, 
         0 
       ); 
       ListView listView = (ListView) findViewById(R.id.list); 
       listView.setAdapter(listAdapter); 
      } 
     } 
} 

我不斷收到一個私人無效updateUI()紅色標記顯示預期(分號)表示錯誤消息。OnCreate預計分號在Android工作室

+1

您正在調用方法 – Zaki

+0

updateUi方法實現在oncreate方法 –

回答

2

試試這個:

public class MainActivity extends AppCompatActivity { 
     private TaskDBHelper helper; 
     private ListAdapter listAdapter; 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       updateUI(); 
       ListView listView = (ListView) findViewById(R.id.list); 
       listView.setAdapter(listAdapter); 
      } 

      private void updateUI(){ 
       helper = new TaskDBHelper(MainActivity.this); 
       SQLiteDatabase sqlDB = helper.getReadableDatabase(); 
       Cursor cursor = sqlDB.query(TaskContract.TABLE, 
         new String[]{TaskContract.Columns._ID, TaskContract.Columns.TASK}, 
         null, null, null, null, null); 

       listAdapter = new SimpleCursorAdapter(
         this, 
         R.layout.task_view, 
         cursor, 
         new String[]{TaskContract.Columns.TASK}, 
         new int[]{R.id.taskTextView}, 
         0 
       ); 
     } 
} 
+0

它說重寫方法應該調用super.oncreate – Synetrix

+0

更新它。添加以下行:super.onCreate(savedInstanceState);順便說一句,你需要在onCreate之後設置你的佈局:setContentView(R.layout.YOUR_ACTIVITY); – Zaki

+0

注意到它和thnks它完美的工作 – Synetrix

2

在Java中,你不能聲明裏面的另一種方法的範圍的方法。您只能在類的範圍內聲明方法。因此,您聲明方法updateUI()的方式無效,應移至類作用域。