1

我正在製作一個應用程序,該應用程序在listview上顯示正在運行的應用程序圖標。 有沒有語法問題(我認爲),但當我啓動應用程序,並嘗試運行活動, 應用程序部隊關閉,我得到threadid=1: thread exiting with uncaught exception (group=0x41088930)和更多的錯誤我該如何解決這個錯誤?我應該使用Asynctask加載圖像列表視圖?或任何解決方案?得到threadid = 1:線程在列表視圖上以未捕獲的異常(group = 0x41088930)退出

(Logcat) 

02-18 14:17:46.700: W/dalvikvm(18370): threadid=1: thread exiting with uncaught exception (group=0x41088930) 
02-18 14:17:46.700: E/AndroidRuntime(18370): FATAL EXCEPTION: main 
02-18 14:17:46.700: E/AndroidRuntime(18370): java.lang.RuntimeException: Unable to start activity ComponentInfo{kr.hybdms.sidepanel/kr.hybdms.sidepanel.LeftSidePanel}: java.lang.NullPointerException 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.ActivityThread.access$600(ActivityThread.java:153) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.os.Handler.dispatchMessage(Handler.java:99) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.os.Looper.loop(Looper.java:137) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.ActivityThread.main(ActivityThread.java:5204) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at java.lang.reflect.Method.invokeNative(Native Method) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at java.lang.reflect.Method.invoke(Method.java:511) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at dalvik.system.NativeStart.main(Native Method) 
02-18 14:17:46.700: E/AndroidRuntime(18370): Caused by: java.lang.NullPointerException 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:330) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.widget.ListView.setAdapter(ListView.java:462) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at kr.hybdms.sidepanel.LeftSidePanel.onCreate(LeftSidePanel.java:59) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.Activity.performCreate(Activity.java:5108) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
02-18 14:17:46.700: E/AndroidRuntime(18370): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2263) 
02-18 14:17:46.700: E/AndroidRuntime(18370): ... 11 more 

(LeftSidePanel.java) 

package kr.hybdms.sidepanel; 


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


import kr.hybdms.sidepanel.PanelArrayAdapter; 
import kr.hybdms.sidepanel.R; 

import kr.hybdms.sidepanel.util.SystemUiHider; 


import android.app.Activity; 
import android.app.ActivityManager; 
import android.content.pm.PackageManager; 
import android.content.pm.PackageManager.NameNotFoundException; 

import android.os.Bundle; 
import android.view.Gravity; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ListView; 
import android.widget.Toast; 

/** 
* An example full-screen activity that shows and hides the system UI (i.e. 
* status bar and navigation/system bar) with user interaction. 
* 
* @see SystemUiHider 
*/ 
public class LeftSidePanel extends Activity implements 
OnItemClickListener { 
ListView listView; 
List<PanelItemDetail> rowItems; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_left_side_panel); 

ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); 
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(10); 
ArrayList<PanelItemDetail> iconarray = new ArrayList<PanelItemDetail>(); 
PackageManager pacMgr = getPackageManager(); 
    for (ActivityManager.RunningTaskInfo runningTask: tasks) 
    { 
    try { 
     iconarray.add(new PanelItemDetail(pacMgr.getApplicationIcon(runningTask.topActivity.getPackageName()))); 
    } catch (NameNotFoundException e) { 
     e.printStackTrace(); 
    } 
    } 

listView = (ListView) findViewById(R.id.panelcontents); 
PanelArrayAdapter adapter = new PanelArrayAdapter(this, 
     R.layout.panelrow, rowItems); 
listView.setAdapter(adapter); 
listView.setOnItemClickListener(this); 
} 

@Override 
public void onItemClick(AdapterView<?> parent, View view, int position, 
    long id) { 
Toast toast = Toast.makeText(getApplicationContext(), 
    "Item " + (position + 1) + ": " + rowItems.get(position), 
    Toast.LENGTH_SHORT); 
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0); 
toast.show(); 
} 
} 

(PanelArrayAdapter.java) 

package kr.hybdms.sidepanel; 

import java.util.List; 

import android.app.Activity; 
import android.content.Context; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 

public class PanelArrayAdapter extends ArrayAdapter<PanelItemDetail> { 
    Context context; 
    public PanelArrayAdapter(Context context, int resourceId, 
      List<PanelItemDetail> items) { 
     super(context, resourceId, items); 
     this.context = context; 
    } 
    /*private view holder class*/ 
    private class ViewHolder { 
     ImageView imageView; 
    } 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder = null; 
     PanelItemDetail rowItem = getItem(position); 
     LayoutInflater mInflater = (LayoutInflater) context 
       .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.panelrow, null); 
      holder = new ViewHolder(); 
      holder.imageView = (ImageView) convertView.findViewById(R.id.appicon); 
      convertView.setTag(holder); 
     } else 
      holder = (ViewHolder) convertView.getTag(); 
     holder.imageView.setImageDrawable(rowItem.getImageId()); 
     return convertView; 
    } 
} 

(PanelItemDetail.java) 

package kr.hybdms.sidepanel; 

import android.graphics.drawable.Drawable; 

public class PanelItemDetail { 
    private Drawable imageId; 
    public PanelItemDetail(Drawable images) { 
     this.imageId = images; 
    } 
    public Drawable getImageId() { 
     return imageId; 
    } 
    public void setImageId(Drawable imageId) { 
     this.imageId = imageId; 
    } 
} 

回答

2

錯誤的是這裏

PanelArrayAdapter adapter = new PanelArrayAdapter(this, 
     R.layout.panelrow, rowItems); 
listView.setAdapter(adapter); 

因爲rowItems尚未初始化。

1

看來,你的源無法找到leftsidepanel

請嘗試以下步驟:

1.首先,檢查您的源是否在錯誤日誌中提及的位置。

2.如果是,請檢查您所做的任何輸入錯誤

3.如果它仍然不能正常工作,它會更容易(在我看來),以創建一個新項目,並重新命名什麼缺少(我已經做了幾次,它一直工作)當然,請確保您複製所有的代碼

相關問題