01-02 22:54:39.409:E / AndroidRuntime(11466):致命异乎寻常:主要 01-02 22:54:39.409:E / AndroidRuntime(11466):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.jhengweipan.travelofdongshan / com.jhengweipan.travelofdongshan.fuyuActivity}:java.lang.NullPointerException 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.ActivityThread.access $ 600(ActivityThread.java:123) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.os.Handler.dispatchMessage(Handler.java:99) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.os.Looper.loop(Looper.java:137) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.ActivityThread.main(ActivityThread.java:4424) 01-02 22:54:39.409:E / AndroidRuntime(11466):at java.lang.reflect.Method.invokeNative(Native Method) 01-02 22:54:39.409:E / AndroidRuntime(11466):at java.lang.reflect.Method.invoke(Method.java:511) 01-02 22:54:39.409:E / AndroidRuntime(11466):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:825) 01-02 22:54:39.409:E / AndroidRuntime(11466):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592) 01-02 22:54:39.409:E / AndroidRuntime(11466):at dalvik.system.NativeStart.main(Native Method) 01-02 22:54:39.409:E / AndroidRuntime(11466):引起:java.lang.NullPointerException 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.content.ContextWrapper.getResources(ContextWrapper.java:81) 01-02 22:54:39.409:E / AndroidRuntime(11466):at com.jhengweipan.travelofdongshan.fuyuActivity。(fuyuActivity.java:18) 01-02 22:54:39.409:E / AndroidRuntime(11466):at java.lang.Class.newInstanceImpl(Native Method) 01-02 22:54:39.409:E / AndroidRuntime(11466):at java.lang.Class.newInstance(Class.java:1319) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.Instrumentation.newActivity(Instrumentation.java:1025) 01-02 22:54:39.409:E / AndroidRuntime(11466):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871) 01-02 22:54:39.409:E / AndroidRuntime(11466):... 11更多 01-02 22:54:39.419:E / dalvikvm(11507):11507 :: IS_UNIFIED_ARM_PROCESS = FALSE,debugFlags = 3
public class fuyuActivity extends Activity {
private String map =getResources().getString(R.string.watch_map);
private Object[]listitem={
map, WelcomeActivity.class,
"2", HeadActivity.class,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_fu_yu);
String[] list = new String[listitem.length/2];
for(int i =0;i<list.length;i++){
list[i]=(String)listitem[i*2];
}
ArrayAdapter<String>adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list);
ListView listview =(ListView)findViewById(R.id.listView1);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Intent i = new Intent(fuyuActivity.this,(Class<?>)listitem[position*2+1]);
startActivity(i);
}
});
}
}
想要多种语言,但一定是个错误,拜托!帮我解决问题,getResourse.getString(R.string ..)这个方法错了吗?请求大师教我
答案 0 :(得分:1)
只有在您的活动中调用getResources().getString(R.string.watch_map)
后才能移动super.onCreate(savedInstanceState)
。在Activity
被调用之后,从super.onCreate()
调用大多数继承的方法是不安全的。