[英]Unreachable Statement
我当前正在创建一个meme生成器,并且收到一条错误消息,内容为unreachable Statement这是什么意思,我该如何解决此问题
这是代码
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);
}
}
重新排序onCreateView看起来像这样;
@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;
}
函数return语句后不能执行任何代码。 请记住,它应该在功能的最后一行。
您在onCreateView中的return语句之后放置了代码语句。 他们将永远无法到达。
@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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.