Wednesday, 21 August 2013

RuntimeException: Unable to start activity Component

RuntimeException: Unable to start activity Component

On this activity i want to show data from SQLite to Listview but it's
still runTime error. Can you check this logcat error to tell me what
happened and how i can do please ?
this is my logcat : i can get data from SQLite now
08-22 12:04:31.011: W/KeyCharacterMap(444): No keyboard for id 0
08-22 12:04:31.021: W/KeyCharacterMap(444): Using default keymap:
/system/usr/keychars/qwerty.kcm.bin
08-22 12:05:35.842: I/item_nickname(444): mao
08-22 12:05:35.842: I/item_fname(444): ho
08-22 12:05:35.842: I/item_lname(444): koj
08-22 12:05:35.842: I/item_nickname(444): YYY
08-22 12:05:35.842: I/item_fname(444): GGG
08-22 12:05:35.851: I/item_lname(444): UUU
08-22 12:05:35.851: I/item_nickname(444): DDD
08-22 12:05:35.851: I/item_fname(444): HHH
08-22 12:05:35.851: I/item_lname(444): TTT
08-22 12:05:35.861: I/item_nickname(444): RICKY
08-22 12:05:35.861: I/item_fname(444): SAMA
08-22 12:05:35.861: I/item_lname(444): SUZA
08-22 12:05:35.861: I/item_nickname(444): LLLL
08-22 12:05:35.861: I/item_fname(444): bbb
08-22 12:05:35.861: I/item_lname(444): MMM
08-22 12:05:35.861: I/item_nickname(444): XXX
08-22 12:05:35.861: I/item_fname(444): VVV
08-22 12:05:35.871: I/item_lname(444): CCC
08-22 12:05:35.871: I/item_nickname(444): UUU
08-22 12:05:35.871: I/item_fname(444): LLL
08-22 12:05:35.871: I/item_lname(444): PPP
08-22 12:05:35.871: I/item_nickname(444): lang
08-22 12:05:35.871: I/item_fname(444): rong
08-22 12:05:35.871: I/item_lname(444): lang
08-22 12:05:35.881: I/item_nickname(444): white
08-22 12:05:35.881: I/item_fname(444): sim
08-22 12:05:35.881: I/item_lname(444): same
08-22 12:05:35.881: I/item_nickname(444): NONG
08-22 12:05:35.881: I/item_fname(444): Bome
08-22 12:05:35.881: I/item_lname(444): NING
08-22 12:05:35.891: D/AndroidRuntime(444): Shutting down VM
08-22 12:05:35.891: W/dalvikvm(444): threadid=1: thread exiting with
uncaught exception (group=0x40015560)
08-22 12:05:35.911: E/AndroidRuntime(444): FATAL EXCEPTION: main
08-22 12:05:35.911: E/AndroidRuntime(444): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.example.sqlite/com.example.sqlite.FriendsListActivity}:
java.lang.IndexOutOfBoundsException: Invalid index 11, size is 11
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.os.Looper.loop(Looper.java:123)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.ActivityThread.main(ActivityThread.java:3683)
08-22 12:05:35.911: E/AndroidRuntime(444): at
java.lang.reflect.Method.invokeNative(Native Method)
08-22 12:05:35.911: E/AndroidRuntime(444): at
java.lang.reflect.Method.invoke(Method.java:507)
08-22 12:05:35.911: E/AndroidRuntime(444): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-22 12:05:35.911: E/AndroidRuntime(444): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-22 12:05:35.911: E/AndroidRuntime(444): at
dalvik.system.NativeStart.main(Native Method)
08-22 12:05:35.911: E/AndroidRuntime(444): Caused by:
java.lang.IndexOutOfBoundsException: Invalid index 11, size is 11
08-22 12:05:35.911: E/AndroidRuntime(444): at
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
08-22 12:05:35.911: E/AndroidRuntime(444): at
java.util.ArrayList.get(ArrayList.java:311)
08-22 12:05:35.911: E/AndroidRuntime(444): at
com.example.sqlite.FriendsListActivity.showAllList(FriendsListActivity.java:56)
08-22 12:05:35.911: E/AndroidRuntime(444): at
com.example.sqlite.FriendsListActivity.onCreate(FriendsListActivity.java:41)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-22 12:05:35.911: E/AndroidRuntime(444): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-22 12:05:35.911: E/AndroidRuntime(444): ... 11 more
08-22 12:05:41.911: I/Process(444): Sending signal. PID: 444 SIG: 9
This is my code FriendsListActivity
package com.example.sqlite;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.example.sqlite.db.FriendsDB;
import com.example.sqlite.entry.FriendEntry;
public class FriendsListActivity extends Activity {
private Context context;
private FriendsDB db;
private SimpleAdapter sAdap;
private ArrayList<FriendEntry> friends;
private TextView hellotext;
private ListView hellolistview;
ArrayList<HashMap<String, String>> MyArrList = new
ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.friendlist_layout);
context = this;
db = new FriendsDB(context);
friends = new ArrayList<FriendEntry>();
showAllList();
}
public void showAllList(){
//view matching
hellotext = (TextView) findViewById(R.id.hellotext);
hellolistview = (ListView) findViewById(R.id.hellolistview);
//select data
friends = db.selectAll();
if(friends.size()==0){
Toast.makeText(context,"You dont have any
friend.",Toast.LENGTH_SHORT).show();
}else{
for (int i = 1;i<=friends.size();i++){
// set value for friends
map = new HashMap<String, String>();
map.put("item_nickname", friends.get(i).getNickname());
map.put("item_fname", friends.get(i).getFname());
map.put("item_lname", friends.get(i).getLname());
Log.i("item_nickname", friends.get(i).getNickname());
Log.i("item_fname", friends.get(i).getFname());
Log.i("item_lname", friends.get(i).getLname());
}
//adapter
hellolistview.setAdapter(new adapter());
}
}
private class adapter extends BaseAdapter{
private Holder holder;
@Override
public int getCount() {
// TODO Auto-generated method stub
return friends.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
//create
if( view == null){
view =
LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_layout,null);
holder = new Holder();
holder.nickname = (TextView)
view.findViewById(R.id.item_nickname);
holder.fname = (TextView)view.findViewById(R.id.item_fname);
holder.lname = (TextView)view.findViewById(R.id.item_lname);
view.setTag(holder);
}else{
holder = (Holder) view.getTag();
}
//assign
holder.nickname.setText(map.get("item_nickname"));
holder.fname.setText(map.get("item_fname"));
holder.lname.setText(map.get("item_lname"));
return view;
}
private class Holder{
public TextView nickname;
public TextView fname;
public TextView lname;
}
}
}
Thank you

No comments:

Post a Comment