简体   繁体   English

java.lang.RuntimeException:无法实例化活动 ComponentInfo - 不是搜索活动

[英]java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - not search activity

I have a problem with my code.我的代码有问题。 can't add class to AndroidManifest.xml.无法将 class 添加到 AndroidManifest.xml。 How do I modify the code to make it work as a standalone class and work?如何修改代码以使其作为独立的 class 工作并正常工作? I need to find a working solution for JSON scrape from URL.我需要从 URL 中找到 JSON 的有效解决方案。

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{cz.mikolashodan.proticovidu/cz.mikolashodan.proticovidu.Statistic}: java.lang.ClassCastException: cz.mikolashodan.proticovidu.Statistic cannot be cast to android.app.Activity

Statistic:统计:

public class Statistic extends Fragment {

private TextView novych_pripadu_cislo, textView14s2;
private ProgressBar progressBar;

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

    View root = inflater.inflate(R.layout.activity_statistic, container, false);

    // call view
    novych_pripadu_cislo = root.findViewById(R.id.novych_pripadu_cislo);
    textView14s2 = root.findViewById(R.id.textView14s2);
    progressBar = root.findViewById(R.id.progress_circular_home);

    // Action Bar title
    getActivity().setTitle("Overview");

    // call Volley
    getData();

    return root;
}

private String getDate(long milliSecond){
    // Mon, 23 Mar 2020 02:01:04 PM
    SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss aaa");

    Calendar calendar= Calendar.getInstance();
    calendar.setTimeInMillis(milliSecond);
    return formatter.format(calendar.getTime());
}

private void getData() {
    RequestQueue queue = Volley.newRequestQueue(getActivity());

    String url = "https://corona.lmao.ninja/all";

    StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            progressBar.setVisibility(View.GONE);

            try {
                JSONObject jsonObject = new JSONObject(response.toString());

                novych_pripadu_cislo.setText(jsonObject.getString("cases"));
                textView14s2.setText("Last Updated"+"\n"+getDate(jsonObject.getLong("updated")));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            progressBar.setVisibility(View.GONE);
            Log.d("Error Response", error.toString());
        }
    });

    queue.add(stringRequest);
}

I drew part of the code here .我在这里画了部分代码。 I'm not a programmer so it's hard for me to find a solution.我不是程序员,所以我很难找到解决方案。 Thank you so much for help me: :)非常感谢你帮助我::)

To AndroidManifest.xml are added only Activities, you got there a Fragment extended class. AndroidManifest.xml只添加了活动,你得到了一个扩展的片段 class。

So you should create activity.所以你应该创建活动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.RuntimeException:无法实例化活动ComponentInfo - NFC访问 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - NFC access java.lang.RuntimeException:无法为 Kotlin MainActivity 实例化活动 ComponentInfo - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo for Kotlin MainActivity java.lang.RuntimeException:无法实例化活动ComponentInfo(PhoneGap) - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo (PhoneGap) Android新手:java.lang.RuntimeException:无法实例化活动ComponentInfo - New to Android: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo java.lang.RuntimeException:无法在 Android Studio 中实例化活动 ComponentInfo - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo in Android Studio java.lang.RuntimeException:无法实例化活动ComponentInfo在点击按钮以击中第二个屏幕活动后 - java.lang.RuntimeException: Unable to instantiate activity ComponentInfo After tapping button to hit second screen activity java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException: Unable to instantiate activity java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException: Unable to instantiate activity java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException: Unable to instantiate the activity java.lang.RuntimeException:无法实例化活动 - java.lang.RuntimeException:Unable to instantiate activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM