2016-09-03 59 views
-1

我正在嘗試在片段中實現日曆。執行自定義日曆時的片段錯誤

Java文件

import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Toast; 

import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.HashSet; 

public class FindPeopleFragment extends Fragment { 

public FindPeopleFragment(){} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    HashSet<Date> events = new HashSet<>(); 
    events.add(new Date()); 
    setHasOptionsMenu(true); 

    CalendarView cv = ((CalendarView)getView().findViewById(R.id.calendar_view)); 
    cv.updateCalendar(events); 

    // assign event handler 
    cv.setEventHandler(new CalendarView.EventHandler() 
    { 
     @Override 
     public void onDayLongPress(Date date) 
     { 
      // show returned day 
      DateFormat df = SimpleDateFormat.getDateInstance(); 
      Toast.makeText(FindPeopleFragment.this.getActivity(), df.format(date), Toast.LENGTH_SHORT).show(); 
     } 
    }); 

} 

@Override 
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) 
{ 
    // Inflate the menu; this adds items to the action bar if it is present. 
    super.onCreateOptionsMenu(menu, inflater); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) 
{ 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) 
    { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

}

這是我收到的錯誤:

錯誤日誌

/Users/stiffmaster/AndroidStudioProjects/Main/app/src/main/java/tiphinbox /main/FindPeopleFragment.java 
Error:(48, 5) error: missing return statement 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
:app:compileDebugJavaWithJavac FAILED 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

問題

如何解決錯誤?

+0

你看過錯誤信息嗎?你有沒有考慮到它告訴你要做什麼? – jwpfox

回答

0

您應該嘗試瞭解錯誤的內容。它說退貨聲明丟失。因此,您應該檢查所有預計將在其方法簽名中返回值的函數,但不會返回。

快速檢查顯示您的onCreateView方法中沒有返回View

祝你好運!