-------------------------------------자바 소스-----------------------------------------
package com.AppView;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import
android.content.pm.ApplicationInfo;
import
android.content.pm.PackageManager;
import
android.graphics.drawable.Drawable;
import android.os.Bundle;
import
android.widget.ArrayAdapter;
import android.widget.ListView;
import
android.widget.TextView;
public class AppViewActivity extends Activity {
ArrayList<String> Items;
ArrayAdapter<String>
Adapter;
ListView list;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final PackageManager pm = getPackageManager();
List<ApplicationInfo> list =
pm.getInstalledApplications(0);
for (ApplicationInfo applicationInfo :
list) {
String name =
String.valueOf(applicationInfo.loadLabel(pm)); // 앱 이름
Items = new ArrayList<String>();
Items.add(name);
Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, Items);
list = (List<ApplicationInfo>) findViewById(R.id.list);
((ListView) list).setAdapter(Adapter);
((ListView) list).setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}
}
--------------------------------------------------------------------------------------
----------------------------main.xml 파일--------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
---------------------------------------------------------------------------------------
저번에 질문 드렸던것에 대해 답변 주신걸로 수정해서 위의 소스로 run 해보았습니다.
근데 소스 자체에는 에러가 없다고 나오는데 run 해보면,
The application AppView has stopped unexpectedly. please try again.
이라고 뜨면서 안되네요....
그래서 로그캣을 봐봤는데 ,
첨부 해놓은 사진 처럼 로그캣이 나오네요....
제 생각에는 java.lang.RuntimeException: Unable to start activity componentInfo{com.activity~~
이 부분이랑, Caused by: java.lang.ClassCastException: android.widget.ListView <---이 부분도
문제가 있는것 같은데, 무슨문제인지 어떻게 해결해야 할지 모르겠습니다...
뭔가 한 부분만 고치면 될 것 같기도 한데 ... 뭔지 아시는분은 슬쩍 댓글 한개 부탁드리겠습니다..!
도와주십쇼....ㅠ.ㅠ




변수의 스코프에 대해 구분하셔야할 듯 하네요~
지역 변수와 전역 변수의 이름이 같을 경우 지역 변수가 우선입니다~
때문의 위의 코드에서 전역 변수로 선언된 ListView 변수명과 지역 변수로 선언된 List 변수명을 다르게 주셔야 하구요~
그리고 ListVIew 뷰 연결시에 자료형 지정이 잘 못 되었네요~ ClassCastException 은 여기서부터 발생된듯 하네요~