J'essaie de créer une liste simple qui utilise des images et des chaînes personnalisées à partir d'un tableau de chaînes, mais quand je l'exécute, elle donne une exception de pointeur nul, disant que storage = null. Je ne suis pas sûr de ce qui se passe, j'ai triplé toutes les épellations des images etc ... et ne peux pas trouver quelque chose peut-être son causé dans le code? Pour les images j'ai créé un nouveau répertoire dans le dossier res drawable et les ai mis dedans, je les ai également ajouté aux autres dossiers drawable juste pour être sûr.Simple image listview Erreur NullPointerException
Voici l'erreur
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whosaidthat.endos.customimagelistview/com.whosaidthat.endos.customimagelistview.MyActivity}: java.lang.NullPointerException: storage == null
Voici l'activité principale
package com.whosaidthat.endos.customimagelistview;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class MyActivity extends ActionBarActivity {
ListView list;
String[] memeTitles;
String[] memeDescriptions;
int[] memeImages = {R.drawable.meme1, R.drawable.meme2, R.drawable.meme3, R.drawable.meme4, R.drawable.meme5, R.drawable.meme6, R.drawable.meme7, R.drawable.meme8, R.drawable.meme9, R.drawable.meme10,R.drawable.meme1, R.drawable.meme2, R.drawable.meme3, R.drawable.meme4, R.drawable.meme5, R.drawable.meme6, R.drawable.meme7, R.drawable.meme8, R.drawable.meme9, R.drawable.meme10};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Resources res = getResources();
res.getStringArray(R.array.titles);
res.getStringArray(R.array.descriptions);
list = (ListView) findViewById(R.id.listView);
lvAdapter adapter = new lvAdapter(this, memeTitles, memeImages, memeDescriptions);
list.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
class lvAdapter extends ArrayAdapter<String>{
int size=1;
Context context;
int[] images;
String[] titleArray;
String[] descriptionArray;
lvAdapter(Context c, String[] titles, int imgs[], String[] descriptions){
super(c, R.layout.single_row, R.id.textView, titles);
this.context = c;
this.images=imgs;
this.titleArray = titles;
this.descriptionArray = descriptions;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Converts the xml based single row into a java based view that we can manipulate and use
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.single_row, parent, false);
ImageView myImage = (ImageView) row.findViewById(R.id.imageView);
myImage.setImageResource(images[position]);
TextView myTitle = (TextView) row.findViewById(R.id.textView);
myTitle.setText(titleArray[position]);
TextView myDescription = (TextView) row.findViewById(R.id.textView2);
myDescription.setText(descriptionArray[position]);
return row;
}
}
Laissez-moi savoir si vous avez besoin d'autre chose
Merci
EDIT
est ici l'ensemble logcat à l'exception
07-27 10:15:03.466 1261-1261/com.whosaidthat.endos.customimagelistview D/dalvikvm﹕ Late-enabling CheckJNI
07-27 10:15:04.056 1261-1261/com.whosaidthat.endos.customimagelistview D/AndroidRuntime﹕ Shutting down VM
07-27 10:15:04.056 1261-1261/com.whosaidthat.endos.customimagelistview W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x416e8ba8)
07-27 10:15:04.076 1261-1261/com.whosaidthat.endos.customimagelistview E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.whosaidthat.endos.customimagelistview, PID: 1261
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whosaidthat.endos.customimagelistview/com.whosaidthat.endos.customimagelistview.MyActivity}: java.lang.NullPointerException: storage == null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: storage == null
at java.util.Arrays$ArrayList.<init>(Arrays.java:38)
at java.util.Arrays.asList(Arrays.java:155)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:141)
at com.whosaidthat.endos.customimagelistview.lvAdapter.<init>(MyActivity.java:67)
at com.whosaidthat.endos.customimagelistview.MyActivity.onCreate(MyActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
07-27 10:15:10.186 1261-1261/com.whosaidthat.endos.customimagelistview I/Process﹕ Sending signal. PID: 1261 SIG: 9
vous aurez besoin pour attacher le logcat entier de l'exception, ces données ne sont pas suffisantes pour une solution – thepoosh