Android に接続された Google アプリ エンジン プロジェクトにカスタム arrayadapter をデプロイする際に重大な問題が発生しました。エミュレーターを使用して Android アプリをデバッグするとエラーが発生し、アプリケーションが停止するため、コードの入力中にエラーは発生しません。私のカスタム アダプター コードは以下のとおりで、デバッガーによるとNullPointerException
46 行目以降にあります。
package com.cheapchase;
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;
import android.widget.TextView;
public class MyListAdapter extends ArrayAdapter<ListItem>{
Context context;
int layoutResourceId;
ListItem data[] = null;
public MyListAdapter(Context context, int layoutResourceId, ListItem[] data){
super(context,layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
ListHolder holder = null;
if(row == null){
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ListHolder();
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
}
else
{
holder = (ListHolder)row.getTag();
}
ListItem listrow = data[position];
holder.txtTitle.setText(listrow.title);
holder.imgIcon.setImageResource(listrow.icon);
return row;
}
static class ListHolder
{
ImageView imgIcon;
TextView txtTitle;
}
}
これは、アダプターを呼び出すアクティビティです。
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
public class StoresList extends Activity{
/**
* The current context.
*/
private ListView listView1;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.store_list);
}
public void onResume(){
super.onResume();
ListItem storelist[] = new ListItem[]{
new ListItem(R.drawable.androidmsg, "test1"),
new ListItem(R.drawable.androidmsg, "test2")
};
MyListAdapter adapter = new MyListAdapter(this, R.layout.listview_item_row, storelist);
listView1 = (ListView)findViewById(R.id.listView1);
/*View header = (View)getLayoutInflater().inflate(R.layout.listview_item_header, null);
listView1.addHeaderView(header);*/
listView1.setAdapter(adapter);
}
// **** end of file
}
これはエラーログです...
06-28 15:16:44.687: W/dalvikvm(1584): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-28 15:16:44.706: E/AndroidRuntime(1584): FATAL EXCEPTION: main
06-28 15:16:44.706: E/AndroidRuntime(1584): java.lang.RuntimeException: Unable to resume activity {com.cheapchase/com.cheapchase.StoresList}: android.app.SuperNotCalledException: Activity {com.cheapchase/com.cheapchase.StoresList} did not call through to super.onResume()
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.os.Looper.loop(Looper.java:130)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-28 15:16:44.706: E/AndroidRuntime(1584): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 15:16:44.706: E/AndroidRuntime(1584): at java.lang.reflect.Method.invoke(Method.java:507)
06-28 15:16:44.706: E/AndroidRuntime(1584): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-28 15:16:44.706: E/AndroidRuntime(1584): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-28 15:16:44.706: E/AndroidRuntime(1584): at dalvik.system.NativeStart.main(Native Method)
06-28 15:16:44.706: E/AndroidRuntime(1584): Caused by: android.app.SuperNotCalledException: Activity {com.cheapchase/com.cheapchase.StoresList} did not call through to super.onResume()
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.Activity.performResume(Activity.java:3834)
06-28 15:16:44.706: E/AndroidRuntime(1584): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
06-28 15:16:44.706: E/AndroidRuntime(1584): ... 12 more
06-28 15:17:19.967: W/ActivityThread(1617): Application com.cheapchase is waiting for the debugger on port 8100...
ご協力ありがとうございました。