2015-07-08 4 views
0

Я в настоящее время создает генератор мем и я получаю и сообщение об ошибке сказав недостижимый заявление, что это означает и как я решить эту проблемуНедоступен Заявление

Вот код

package com.example.curtis.memegenerator; 

import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 

public class BottomPictureFragment 
    extends Fragment { 

    private static TextView topMemeText; 
    private static TextView bottomMemeText; 

    // Variables topmemetext and bottommemetext 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.bottom_picture_fragment, container, false); 
     return view; 
     topMemeText = (TextView) view.findViewById(R.id.topMemeText); 
     bottomMemeText = (TextView) view.findViewById(R.id.bottomMemeText); 
    } 

    //method public void , two parameters 
    public void setTopMemeText(String top, String bottom) { 
     topMemeText.setText(top); 
     bottomMemeText.setText(bottom); 
    } 
} 
+0

У вас есть код после 'return view;' комментарий или удалить код ... или переместить оператор return в конец – Populus

+0

это означает 'return view;' должно быть последним утверждением этого метода – EpicPandaForce

ответ

6

Измените порядок на CreateView, чтобы выглядеть так;

@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,@Nullable Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.bottom_picture_fragment,container,false); 
    topMemeText = (TextView) view.findViewById(R.id.topMemeText); 
    bottomMemeText = (TextView) view.findViewById(R.id.bottomMemeText); 
    return view; 
} 

Любой код не может быть выполнен после оператора возврата в fuction. Помните, что это должно быть в последней строке функции.

+0

@ 404notfound- it work благодаря – user1727257

1

Вы размещенные операторы кода после вашего оператора return в onCreateView. Они никогда не будут достигнуты.

@Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,@Nullable Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.bottom_picture_fragment,container,false); 
    return view; //<- code returns from method here. It will never proceed 
    topMemeText = (TextView) view.findViewById(R.id.topMemeText); 
    bottomMemeText = (TextView) view.findViewById(R.id.bottomMemeText); 
}