英文:
Handler is Unreachable Statement
问题
我正在创建一个应用程序,它从我的数据库(000webhost)进行连接,并且我正在使用这个[http url连接][1]。
以下是我的代码:
```java
public class RegisterFragment extends Fragment {
    public RegisterFragment() {
        // 必要的空公共构造函数
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // 为此片段填充布局
        return inflater.inflate(R.layout.fragment_register, container, false);
        // 首先启动进度条(设置可见性为VISIBLE)
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
                if (fetchData.startFetch()) {
                    if (fetchData.onComplete()) {
                        String result = fetchData.getResult();
                        // 结束进度条(将可见性设置为GONE)
                    }
                }
            }
        });
    }
}
而且它告诉我Handler部分是
>不可达语句
有人可以指出为什么会出现错误吗?
提前谢谢。
<details>
<summary>英文:</summary>
I am creating an app that connects from my database(000webhost) and I am using this
for the [http url connection][1] . 
And here's my code
public class RegisterFragment extends Fragment {
public RegisterFragment() {
    // Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_register, container, false);
    //Start ProgressBar first (Set visibility VISIBLE)
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            FetchData fetchData = new FetchData("https://projects.vishnusivadas.com/AdvancedHttpURLConnection/readTest.php");
            if (fetchData.startFetch()) {
                if (fetchData.onComplete()) {
                    String result = fetchData.getResult();
                    //End ProgressBar (Set visibility to GONE)
                }
            }
        }
    });
}
}
And it is telling me that the ```Handler``` part is
>Unreachable Statement
Could someone point out why it is having an error.
Thank you in advance
  [1]: https://github.com/VishnuSivadasVS/Advanced-HttpURLConnection
</details>
# 答案1
**得分**: 1
你在 Handler 代码的上方有一个返回语句。
    return inflater.inflate(R.layout.fragment_register, container, false);
因此,在达到 Handler 之前,该函数将会返回。
解释:https://www.geeksforgeeks.org/return-keyword-java/
<details>
<summary>英文:</summary>
You have a return statement just above the Handler code.
    return inflater.inflate(R.layout.fragment_register, container, false);
Therefore the function will return before ever reaching the Handler.
Explaination: https://www.geeksforgeeks.org/return-keyword-java/
</details>
				通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论