我创建这个程序在SwipeView中有一个listView,但是我测试了apk总是停止, 我试着提出断点,但我找不到问题, 这是JAVA:
package com.sapires.Joes;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.sapires.Pizza.R;
public class Ementa extends Fragment {
ListView list;
private Context context;
Context cont;
String[] Mtitles;
String[] Mdescriptions;
int[] images = { R.drawable.um, R.drawable.dois, R.drawable.tres,
R.drawable.quatro,R.drawable.cinco,R.drawable.seis };
@Override
public void onAttach(Activity activity) {
context = activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View android = inflater.inflate(R.layout.ementa_2, container, false);
Resources res = getResources();
Mtitles = res.getStringArray(R.array.titles);
Mdescriptions = res.getStringArray(R.array.descriptions);
list = (ListView) android.findViewById(R.id.listView2);
VivzAdapter adapter = new VivzAdapter(context, Mtitles, images, Mdescriptions);
list.setAdapter(adapter);
return android;
}
}
class VivzAdapter extends ArrayAdapter<String> {
Context context;
int[] images;
String[] titleArray;
String[] descriptionArray;
VivzAdapter(Context c,String[] titles, int imgs[], String[] desc) {
super(c, R.layout.auxementa_2, R.id.textView3, titles);
this.context = c;
this.images = imgs;
this.titleArray = titles;
this.descriptionArray = desc;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.auxementa_2, parent, false);
ImageView myImage = (ImageView) row.findViewById(R.id.imageView3);
TextView myTitle = (TextView) row.findViewById(R.id.textView3);
TextView myDescription = (TextView) row.findViewById(R.id.textView4);
myImage.setImageResource(images[position]);
myTitle.setText(titleArray[position]);
myDescription.setText(descriptionArray[position]);
return row;
}
}
这是错误:
08-05 23:49:13.474: E/MoreInfoHPW_ViewGroup(16938): Parent view is not a TextView
08-05 23:49:13.484: D/skia(16938): GFXPNG PNG bitmap created width:144 height:144 bitmap id is 273
08-05 23:49:13.484: I/PersonaManager(16938): getPersonaService() name persona_policy
08-05 23:49:13.644: D/AndroidRuntime(16938): Shutting down VM
08-05 23:49:13.654: E/AndroidRuntime(16938): FATAL EXCEPTION: main
08-05 23:49:13.654: E/AndroidRuntime(16938): Process: com.sapires.Pizza, PID: 16938
08-05 23:49:13.654: E/AndroidRuntime(16938): android.support.v4.app.SuperNotCalledException: Fragment Ementa{68594c68 #1 id=0x7f070014 android:switcher:2131165204:1} did not call through to super.onAttach()
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:900)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.View.measure(View.java:17478)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.View.measure(View.java:17478)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
08-05 23:49:13.654: E/AndroidRuntime(16938): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:412)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.View.measure(View.java:17478)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5364)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
08-05 23:49:13.654: E/AndroidRuntime(16938): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2548)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.View.measure(View.java:17478)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2262)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1391)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1590)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6585)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.Choreographer.doCallbacks(Choreographer.java:603)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.Choreographer.doFrame(Choreographer.java:573)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.os.Handler.handleCallback(Handler.java:733)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.os.Handler.dispatchMessage(Handler.java:95)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.os.Looper.loop(Looper.java:136)
08-05 23:49:13.654: E/AndroidRuntime(16938): at android.app.ActivityThread.main(ActivityThread.java:5579)
08-05 23:49:13.654: E/AndroidRuntime(16938): at java.lang.reflect.Method.invoke(Native Method)
08-05 23:49:13.654: E/AndroidRuntime(16938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
08-05 23:49:13.654: E/AndroidRuntime(16938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
答案 0 :(得分:0)
只需修改:
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
context = activity;
}