-1
私はアンドロイドの開発を学習しており、私のアプリで連絡先の詳細を表示する問題があります。私は取得できません商品の詳細
連絡先アクティビティのアイテムをクリックすると、アプリがハングアップします。
お願いします。
これは連絡先リストのアクティビティアプリです。ここでConatctDetailItem
public class ContactDetailItem extends AppCompatActivity {
TextView n, ph, surn;
ImageView imgC;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_detail_item);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
n = (TextView) findViewById(R.id.contactName);
surn = (TextView) findViewById(R.id.contactSurname);
ph = (TextView) findViewById(R.id.contactPhone);
imgC = (ImageView) findViewById(R.id.imgContact);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
ContactHelper contactHelper = new ContactHelper();
ListViewActivity3 lv = new ListViewActivity3();
int position = bundle.getInt(ListViewActivity3.Key_Postion);
n.setText(lv.listAdapter.get(position).getName());
surn.setText(lv.listAdapter.get(position).getSurname());
ph.setText(lv.listAdapter.get(position).getPhone());
imgC.setImageResource(lv.listAdapter.get(position).getPhoto());
}
}
}
public class ListViewActivity3 extends AppCompatActivity {
ListView listView;
List<ContactHelper> listAdapter;
public static final String Key_Postion = "keyPosition" ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view3);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
listAdapter = new ArrayList<ContactHelper>();
listAdapter.clear();
listAdapter.add(new ContactHelper("achref", "Tunisien", "2222222", R.drawable.imagesand));
listAdapter.add(new ContactHelper("achref", "Tunisien", "2222222", R.drawable.imagesand));
listAdapter.add(new ContactHelper("achref", "Tunisien", "2222222", R.drawable.imagesand));
listAdapter.add(new ContactHelper("achref", "Tunisien", "2222222", R.drawable.imagesand));
listAdapter.add(new ContactHelper("achref", "Tunisien", "2222222", R.drawable.imagesand));
listView = (ListView) findViewById(R.id.listviewCustomAdapter);
listView.setAdapter(new AdapterCustom(ListViewActivity3.this, R.layout.listviewitem1, listAdapter));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i3 = new Intent(ListViewActivity3.this, ContactDetailItem.class);
i3.putExtra(Key_Postion, position);
startActivity(i3);
}
});
}
}
、これはlogcatです。 ContactDetailItem
で
com.example.achre.activityapp E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.achre.activityapp/com.example.achre.activityapp.ContactDetailItem}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.achre.activityapp.ContactDetailItem.onCreate(ContactDetailItem.java:50)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
を実装する必要があります
をあなたは新しい(空を作成している – wvdz
logcatのスタックトレースを含めます)ListViewActivity3、なぜそこに何もありません。連絡先に必要なすべてのデータは、インテントの余分なものに渡す必要があります。 –
ListViewActivity3は連絡先のリストのアクティビティで、アダプタのリストを取得するためにinstancietedしました – achref05