gpt4 book ai didi

java - 应用程序正在运行,但现在意外关闭

转载 作者:行者123 更新时间:2023-11-29 04:12:26 26 4
gpt4 key购买 nike

<分区>

昨天,我的应用程序 shopapp 正常运行。但是今天当我在 AVD 中打开它时,它意外地关闭了。我检查了 Log Cat 中的错误日志,但它似乎让我有些困惑。

我检查了 duplicate question here但其中包含由 findViewById 引起的错误日志。

错误日志:

--------- beginning of crash
2019-01-22 12:21:52.836 4855-4855/com.local.xspac.shopapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.local.xspac.shopapp, PID: 4855
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.local.xspac.shopapp/com.local.xspac.shopapp.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.local.xspac.shopapp.MainActivity> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.InstantiationException: java.lang.Class<com.local.xspac.shopapp.MainActivity> cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

主要 Activity :

package com.local.xspac.shopapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public abstract class MainActivity extends AppCompatActivity {

String[] listviewTitle = new String[] {
"Shop One", "Shop Two", "Shop Three", "Shop Four",
"Shop Five", "Shop Six", "Shop Seven", "Shop Eight",
};
String[] listviewURL = new String[] {
"https://google.com", "https://bing.com", "https://yahoo.com", "https://duckduckgo.com", "https://stackoverflow.com/",
"https://thehackernews.com", "https://techviral.net", "https://amazon.in",
};
String[] listviewShortDescription = new String[]{
"Shop One Short Description", "Shop Two Short Description", "Shop Three Short Description", "Shop Four Short Description",
"Shop Five Short Description", "Shop Six Short Description", "Shop Seven Short Description", "Shop Eight Short Description",
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<HashMap<String, String>> aList = new ArrayList<>();
for (int i = 0; i < 8; i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("listview_title", listviewTitle[i]);
hm.put("listview_discription", listviewShortDescription[i]);
hm.put("listview_url", listviewURL[i]);

aList.add(hm);
}
//String[] from = {"listview_image", "listview_title", "listview_description"};
String[] from = {"listview_url", "listview_title", "listview_discription"};
int[] to = {R.id.listview_item_url, R.id.listview_item_title, R.id.listview_item_short_description};

//int[] to = {R.id.listview_item_title, R.id.listview_item_short_description};

SimpleAdapter simpleAdapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_activity, from, to);
ListView androidListView = (ListView) findViewById(R.id.list_view);
androidListView.setAdapter(simpleAdapter);
androidListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
//
}
});
}
public void buttonClick(View view) {
String currentURL = null;
ViewGroup parent = (ViewGroup) view.getParent();
TextView child = (TextView) parent.findViewById(R.id.listview_item_url);
currentURL = child.getText().toString();
Intent logwebview = new Intent(MainActivity.this, WebViewActivity.class);
logwebview.putExtra("CurrentUrL",String.valueOf(currentURL));
startActivity(logwebview);
}
public void fetchClick (View view) {
Intent fetchDetails = new Intent(MainActivity.this, API.class);
startActivity(fetchDetails);
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com