0

I have this code but it doesn't want to work.

also, Main.java line 76 includes this in my onCreate:

setListAdapter(new ImageAndTextAdapter(ctx, R.layout.lchs_item,
    items, icons));

imageandtextadapter.java:

public class ImageAndTextAdapter extends ArrayAdapter<String> {

private LayoutInflater mInflater;

private String[] mStrings;
private TypedArray mIcons;

private int mViewResourceId;

public ImageAndTextAdapter(Context ctx, int viewResourceId,
        String[] strings, TypedArray icons) {
    super(ctx, viewResourceId, strings);

    mInflater = (LayoutInflater)ctx.getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);

    mStrings = strings;
    mIcons = icons;

    mViewResourceId = viewResourceId;
}

@Override
public int getCount() {
    return mStrings.length;
}

@Override
public String getItem(int position) {
    return mStrings[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    convertView = mInflater.inflate(mViewResourceId, null);

    ImageView iv = (ImageView)convertView.findViewById(R.id.item_icon);
    iv.setImageDrawable(mIcons.getDrawable(position));

    TextView tv = (TextView)convertView.findViewById(R.id.item_text);
    tv.setText(mStrings[position]);

    return convertView;
}
    }

Logcat

`02-16 00:19:36.867: E/InputManager-JNI(379): An exception was thrown by callback 'interceptKeyBeforeQueueing'.
02-16 00:19:36.867: E/AndroidRuntime(27101): FATAL EXCEPTION: main
02-16 00:19:36.867: E/AndroidRuntime(27101): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twk95.lchs.browser/com.twk95.lchs.browser.Main}: java.lang.ClassCastException: com.android.internal.policy.impl.PhoneLayoutInflater cannot be cast to org.holoeverywhere.LayoutInflater
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.ActivityThread.access$600(ActivityThread.java:150)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.os.Looper.loop(Looper.java:137)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.ActivityThread.main(ActivityThread.java:5195)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at java.lang.reflect.Method.invokeNative(Native Method)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at java.lang.reflect.Method.invoke(Method.java:511)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at dalvik.system.NativeStart.main(Native Method)
02-16 00:19:36.867: E/AndroidRuntime(27101): Caused by: java.lang.ClassCastException: com.android.internal.policy.impl.PhoneLayoutInflater cannot be cast to org.holoeverywhere.LayoutInflater
02-16 00:19:36.867: E/AndroidRuntime(27101):    at com.twk95.lchs.browser.ImageAndTextAdapter.<init>(ImageAndTextAdapter.java:27)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at com.twk95.lchs.browser.Main.onCreate(Main.java:76)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.Activity.performCreate(Activity.java:5104)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-16 00:19:36.867: E/AndroidRuntime(27101):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
02-16 00:19:36.867: E/AndroidRuntime(27101):    ... 11 more
02-16 00:19:36.875: E/InputManager-JNI(379): java.lang.NullPointerException
02-16 00:19:36.875: E/InputManager-JNI(379):    at com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeQueueing(PhoneWindowManager.java:3832)
02-16 00:19:36.875: E/InputManager-JNI(379):    at com.android.server.wm.InputMonitor.interceptKeyBeforeQueueing(InputMonitor.java:337)
02-16 00:19:36.875: E/InputManager-JNI(379):    at com.android.server.input.InputManagerService.interceptKeyBeforeQueueing(InputManagerService.java:1317)
02-16 00:19:36.875: E/InputManager-JNI(379):    at dalvik.system.NativeStart.run(Native Method)`

if you want more code, just ask. thanks for the help!

EDIT: I added more code. Also, system32 and ebarrenchea's suggestions didn't work. EDIT2: Answered my own question. Solution below

TheWizKid95
  • 721
  • 6
  • 16
  • do you think this code will be sufficient to identity your issue...post full code – Pragnani Feb 16 '13 at 05:36
  • It was a pretty good start and the OP said would be glad to add more, trying not to do a code dump. I think it was a valid attempt and we should only criticize those that don't even try...just my opinion – codeMagic Feb 16 '13 at 05:41
  • in your oncreate you foget `this` here `this.mViewResourceId = mViewResourceId ` – William Kinaan Feb 16 '13 at 06:45

3 Answers3

0

I've never used holo-everywhere before but it seems your problem is in this line:

02-16 00:19:36.867: E/AndroidRuntime(27101): Caused by: java.lang.ClassCastException: com.android.internal.policy.impl.PhoneLayoutInflater cannot be cast to org.holoeverywhere.LayoutInflater
02-16 00:19:36.867: E/AndroidRuntime(27101):    at com.twk95.lchs.browser.ImageAndTextAdapter.<init>(ImageAndTextAdapter.java:27)

Your mLayoutInflater should be of type android.view.LayoutInflater, which can be solved with a simple:

import android.view.LayoutInflater;
ebarrenechea
  • 3,775
  • 1
  • 31
  • 37
  • importing android.view.LayoutInflater rather than org.holoeverywhere.LayoutInflater didn't seem to do anything. – TheWizKid95 Feb 16 '13 at 05:58
0

looks like i got it guys. I was implementing everything right, I just had the list adapter set wrong on my Main.activity

Edited it from: setListAdapter(new ImageAndTextAdapter(ctx, R.layout.lchs_item, items, icons));

To: this.setListAdapter(new ImageAndTextAdapter(this, R.layout.lchs_item, items, icons));

TheWizKid95
  • 721
  • 6
  • 16
0

mInflater = LayoutInflater.from(ctx);
Definitely be HoloEverywere's LayoutInflater.

Prototik
  • 935
  • 4
  • 7