我一直在尝试查看项目的详细信息,只要我点击ListView
即可。但我不断收到错误,说无法实例化活动。致命错误:无法激活活动组件
这里是我的logcat
10-29 03:01:44.516: E/AndroidRuntime(1252): FATAL EXCEPTION: main
10-29 03:01:44.516: E/AndroidRuntime(1252): Process: com.esggoa.iffi_app, PID: 1252
10-29 03:01:44.516: E/AndroidRuntime(1252): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.esggoa.iffi_app/com.esggoa.iffi_app.model.SingleItemView}: java.lang.NullPointerException
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.os.Handler.dispatchMessage(Handler.java:102)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.os.Looper.loop(Looper.java:136)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-29 03:01:44.516: E/AndroidRuntime(1252): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 03:01:44.516: E/AndroidRuntime(1252): at java.lang.reflect.Method.invoke(Method.java:515)
10-29 03:01:44.516: E/AndroidRuntime(1252): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-29 03:01:44.516: E/AndroidRuntime(1252): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-29 03:01:44.516: E/AndroidRuntime(1252): at dalvik.system.NativeStart.main(Native Method)
10-29 03:01:44.516: E/AndroidRuntime(1252): Caused by: java.lang.NullPointerException
10-29 03:01:44.516: E/AndroidRuntime(1252): at com.esggoa.iffi_app.model.SingleItemView.<init>(SingleItemView.java:26)
10-29 03:01:44.516: E/AndroidRuntime(1252): at java.lang.Class.newInstanceImpl(Native Method)
10-29 03:01:44.516: E/AndroidRuntime(1252): at java.lang.Class.newInstance(Class.java:1208)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-29 03:01:44.516: E/AndroidRuntime(1252): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
10-29 03:01:44.516: E/AndroidRuntime(1252): ... 11 more
而且因为它规定
Caused by: java.lang.NullPointerException
10-29 03:01:44.516: E/AndroidRuntime(1252): at com.esggoa.iffi_app.model.SingleItemView.<init>(SingleItemView.java:26)
我张贴下面
public class SingleItemView extends Fragment {
// Declare Variables
String rank;
String country;
String population;
String flag;
String position;
ImageLoader imageLoader = new ImageLoader(getActivity().getApplicationContext());
private FragmentActivity fa;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.singleitemview, container, false);
return rootView;
}
@Override
public void onStart() {
super.onStart();
// Get the view from singleitemview.xml
Intent i = new Intent(fa, SingleItemView.class);
// Get the result of rank
rank = i.getStringExtra("rank");
// Get the result of country
country = i.getStringExtra("country");
// Get the result of population
population = i.getStringExtra("population");
// Get the result of flag
flag = i.getStringExtra("flag");
// Locate the TextViews in singleitemview.xml
TextView txtrank = (TextView) getView().findViewById(R.id.rank);
TextView txtcountry = (TextView) getView().findViewById(R.id.country);
TextView txtpopulation = (TextView) getView().findViewById(R.id.population);
// Locate the ImageView in singleitemview.xml
ImageView imgflag = (ImageView) getView().findViewById(R.id.flag);
// Set results to the TextViews
txtrank.setText(rank);
txtcountry.setText(country);
txtpopulation.setText(population);
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
imageLoader.DisplayImage(flag, imgflag);
}
}
我SingleItemView.java任何帮助表示赞赏
10-29 05:20:12.075: E/AndroidRuntime(1108): FATAL EXCEPTION: main
10-29 05:20:12.075: E/AndroidRuntime(1108): Process: com.esggoa.iffi_app, PID: 1108
10-29 05:20:12.075: E/AndroidRuntime(1108): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.esggoa.iffi_app/com.esggoa.iffi_app.model.SingleItemView}: java.lang.ClassCastException: com.esggoa.iffi_app.model.SingleItemView cannot be cast to android.app.Activity
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.os.Handler.dispatchMessage(Handler.java:102)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.os.Looper.loop(Looper.java:136)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-29 05:20:12.075: E/AndroidRuntime(1108): at java.lang.reflect.Method.invokeNative(Native Method)
10-29 05:20:12.075: E/AndroidRuntime(1108): at java.lang.reflect.Method.invoke(Method.java:515)
10-29 05:20:12.075: E/AndroidRuntime(1108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-29 05:20:12.075: E/AndroidRuntime(1108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-29 05:20:12.075: E/AndroidRuntime(1108): at dalvik.system.NativeStart.main(Native Method)
10-29 05:20:12.075: E/AndroidRuntime(1108): Caused by: java.lang.ClassCastException: com.esggoa.iffi_app.model.SingleItemView cannot be cast to android.app.Activity
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-29 05:20:12.075: E/AndroidRuntime(1108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
10-29 05:20:12.075: E/AndroidRuntime(1108): ... 11 more
可否请你试着去了解和调试代码,作为开发人员,你会遇到数百这些情况。 – meh 2014-10-29 07:14:55
@meh我是非常新的android和我不知道调试技术 – 2014-10-29 08:03:28
调试你的代码是最好的学习方式 – meh 2014-10-29 08:14:14