我有ListFragment,我想通过使用onListItemClick()从每个列表开始新的活动但是她点击列表应用程序总是崩溃停止工作请请看下面我的代码 请帮助谢谢。
OldTestamentFragment.java
package com.cambobox.slidemenu.model.model;
import android.app.ListFragment;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.cambobox.slidemenu.R;
import com.cambobox.slidemenu.model.adapter.OldtestamentAdapter;
public class OldTestamentFragment extends ListFragment {
String[] old_testament_list;
Typeface font;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
{
//List view with custom adapter
old_testament_list = getResources().getStringArray(R.array.old_testament_list);
setListAdapter(new OldtestamentAdapter(getActivity(),old_testament_list));
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
switch (position){
case 0:
Intent intent = new Intent(v.getContext(),Chapter.class);
startActivity(intent);
break;
.......
.......
}
}
}
Chapter.java
package com.cambobox.slidemenu.model.model;
import android.app.ListActivity;
import android.os.Bundle;
import com.cambobox.slidemenu.R;
import com.cambobox.slidemenu.model.adapter.ChapterAdapter;
public class Chapter extends ListActivity {
String[] chapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
chapter = getResources().getStringArray(R.array.genesis);
setListAdapter(new ChapterAdapter(this,chapter));
}
}
chapter_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/chapter_list"
android:text="@+id/chapter_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
ChapterAdapter.java
package com.cambobox.slidemenu.model.adapter;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.cambobox.slidemenu.R;
import com.cambobox.slidemenu.model.model.Chapter;
public class ChapterAdapter extends ArrayAdapter<String> {
public final Context context;
public final String[] value;
Typeface font;
public ChapterAdapter(Context context, String[] value){
super(context, R.layout.chapter_activity,value);
this.context = context;
this.value = value;
font = Typeface.createFromAsset(context.getAssets(),"font/khmerbibleregular.ttf");
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.chapter_activity,parent,false);
TextView textView = (TextView) rowView.findViewById(R.id.chapter_list);
textView.setTypeface(font);
textView.setTextSize(30);
textView.setText(value[position]);
return rowView;
}
}
logcat的
05-21 15:13:02.838 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.858 3890-3890/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 25K, 2% free 9358K/9508K, paused 13ms, total 13ms
05-21 15:13:02.868 3890-3890/com.cambobox.slidemenu I/dalvikvm-heap﹕ Grow heap (frag case) to 11.068MB for 1992656-byte allocation
05-21 15:13:02.878 3890-3899/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 3K, 2% free 11301K/11456K, paused 16ms, total 16ms
05-21 15:13:02.918 3890-3890/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 3K, 2% free 11298K/11456K, paused 13ms, total 13ms
05-21 15:13:02.928 3890-3890/com.cambobox.slidemenu I/dalvikvm-heap﹕ Grow heap (frag case) to 12.962MB for 1992656-byte allocation
05-21 15:13:02.938 3890-3899/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 2% free 13244K/13404K, paused 15ms, total 15ms
05-21 15:13:02.968 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.978 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.978 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.978 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.988 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.988 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.988 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.998 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:02.998 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:03.008 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:03.008 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:03.008 3890-3890/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:07.312 3890-3890/com.cambobox.slidemenu D/AndroidRuntime﹕ Shutting down VM
05-21 15:13:07.312 3890-3890/com.cambobox.slidemenu W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41544ba8)
05-21 15:13:07.322 3890-3890/com.cambobox.slidemenu E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.cambobox.slidemenu, PID: 3890
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.cambobox.slidemenu/com.cambobox.slidemenu.model.model.Testing}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1541)
at android.app.Activity.startActivityFromFragment(Activity.java:3957)
at android.app.Activity.startActivityFromFragment(Activity.java:3932)
at android.app.Fragment.startActivity(Fragment.java:1054)
at android.app.Fragment.startActivity(Fragment.java:1033)
at com.cambobox.slidemenu.model.model.OldTestamentFragment.onListItemClick(OldTestamentFragment.java:42)
at android.app.ListFragment$2.onItemClick(ListFragment.java:160)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
at android.widget.AbsListView$3.run(AbsListView.java:3638)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
05-21 15:13:10.345 3890-3890/com.cambobox.slidemenu I/Process﹕ Sending signal. PID: 3890 SIG: 9
05-21 15:13:16.241 3940-3940/com.cambobox.slidemenu I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
05-21 15:13:16.261 3940-3940/com.cambobox.slidemenu D/OpenGLRenderer﹕ Enabling debug mode 0
05-21 15:13:16.361 3940-3940/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 163K, 3% free 9330K/9524K, paused 13ms, total 13ms
05-21 15:13:21.536 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.556 3940-3940/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 23K, 2% free 9357K/9524K, paused 11ms, total 11ms
05-21 15:13:21.556 3940-3940/com.cambobox.slidemenu I/dalvikvm-heap﹕ Grow heap (frag case) to 11.067MB for 1992656-byte allocation
05-21 15:13:21.566 3940-3949/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 2K, 2% free 11301K/11472K, paused 11ms, total 11ms
05-21 15:13:21.606 3940-3940/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed 2K, 2% free 11299K/11472K, paused 12ms, total 12ms
05-21 15:13:21.606 3940-3940/com.cambobox.slidemenu I/dalvikvm-heap﹕ Grow heap (frag case) to 12.962MB for 1992656-byte allocation
05-21 15:13:21.616 3940-3949/com.cambobox.slidemenu D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 2% free 13244K/13420K, paused 11ms, total 11ms
05-21 15:13:21.636 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.636 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.646 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.646 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.646 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.646 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.646 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.656 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.656 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.656 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.656 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:21.666 3940-3940/com.cambobox.slidemenu W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f080043}
05-21 15:13:25.430 3940-3940/com.cambobox.slidemenu D/AndroidRuntime﹕ Shutting down VM
05-21 15:13:25.430 3940-3940/com.cambobox.slidemenu W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41544ba8)
05-21 15:13:25.430 3940-3940/com.cambobox.slidemenu E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.cambobox.slidemenu, PID: 3940
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.cambobox.slidemenu/com.cambobox.slidemenu.model.model.Testing}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1541)
at android.app.Activity.startActivityFromFragment(Activity.java:3957)
at android.app.Activity.startActivityFromFragment(Activity.java:3932)
at android.app.Fragment.startActivity(Fragment.java:1054)
at android.app.Fragment.startActivity(Fragment.java:1033)
at com.cambobox.slidemenu.model.model.OldTestamentFragment.onListItemClick(OldTestamentFragment.java:42)
at android.app.ListFragment$2.onItemClick(ListFragment.java:160)
at android.widget.AdapterView.performItemClick(AdapterView.java:299)
at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
at android.widget.AbsListView$3.run(AbsListView.java:3638)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
05-21 15:13:28.313 3940-3940/com.cambobox.slidemenu I/Process﹕ Sending signal. PID: 3940 SIG: 9
答案 0 :(得分:0)
无法找到显式活动类 {com.cambobox.slidemenu / com.cambobox.slidemenu.model.model.Testing};
您是否在AndroidManifest.xml中声明了此活动?
只需复制粘贴。您需要在清单中声明您的活动。