gpt4 book ai didi

java.lang.class - java.lang.RuntimeException : Unable to start activity ComponentInfo: java. lang.NullPointerException: storage == null

转载 作者:行者123 更新时间:2023-12-03 13:27:01 25 4
gpt4 key购买 nike

*我正在尝试将项目动态添加到 ListView 中。但是,我遇到了运行时异常。请帮忙。
全局变量“值”有问题吗?
我尝试通过打印日志进行调试,并且能够看到存储在变量 * 中的值

public class FriendsActivity extends ListFragment implements TabListener {
private Fragment mFragment;
private String[] values;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.activity_friends);
}

@SuppressWarnings("deprecation")
public void onActivityCreated(Bundle savedInstanceState) {
setHasOptionsMenu(true);
super.onActivityCreated(savedInstanceState);
String su = User.getLoggedInUsername();
friends.query(friends.class, new StackMobQuery().field(new StackMobQueryField("uname").isEqualTo(su)), new StackMobQueryCallback<friends>(){

@Override
public void failure(StackMobException arg0) {
// TODO Auto-generated method stub

}

public void success(List<friends> arg0) {
// TODO Auto-generated method stub
if(arg0.size()>0){
FriendsActivity.this.values = new String[arg0.size()];
for(int i=0;i<arg0.size();i++){
friends us = arg0.get(i);
values[i] = us.getUname();
}
for(int i=0;i<values.length;i++)
Log.i("Friends",values[i]);
}
else{
values = new String[]{"xyz","abc","dbz"};

}
}

});
//String uname=User.getLoggedInUsername();
//Log.i("User Name",uname);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}

这是错误列表
05-27 16:42:03.667: E/Trace(814): error opening trace file: No such file or directory     (2)
05-27 16:46:17.718: E/AndroidRuntime(814): FATAL EXCEPTION: main
05-27 16:46:17.718: E/AndroidRuntime(814): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.cloudchat/com.myapp.cloudchat.HomeScreenActivity}: java.lang.NullPointerException: storage == null
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.os.Looper.loop(Looper.java:137)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-27 16:46:17.718: E/AndroidRuntime(814): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 16:46:17.718: E/AndroidRuntime(814): at java.lang.reflect.Method.invoke(Method.java:511)
05-27 16:46:17.718: E/AndroidRuntime(814): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-27 16:46:17.718: E/AndroidRuntime(814): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-27 16:46:17.718: E/AndroidRuntime(814): at dalvik.system.NativeStart.main(Native Method)
05-27 16:46:17.718: E/AndroidRuntime(814): Caused by: java.lang.NullPointerException: storage == null
05-27 16:46:17.718: E/AndroidRuntime(814): at java.util.Arrays$ArrayList.<init>(Arrays.java:38)
05-27 16:46:17.718: E/AndroidRuntime(814): at java.util.Arrays.asList(Arrays.java:154)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128)
05-27 16:46:17.718: E/AndroidRuntime(814): at com.myapp.cloudchat.FriendsActivity.onActivityCreated(FriendsActivity.java:74)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.Fragment.performActivityCreated(Fragment.java:1703)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.BackStackRecord.run(BackStackRecord.java:682)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.Activity.performStart(Activity.java:5113)
05-27 16:46:17.718: E/AndroidRuntime(814): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
05-27 16:46:17.718: E/AndroidRuntime(814): ... 11 more
05-27 16:46:20.428: E/Trace(866): error opening trace file: No such file or directory (2)

最佳答案

当数组参数传递给 "storage == null" 时,会引发此特定异常 ( ArrayAdapter(Context, int, T[]) )一片空白。 (更具体地说,当它试图创建一个新的 ArrayList 包裹在你的空数组周围时,它是从 Arrays.java 抛出的。)

变量values应该没有问题本身,但你绝对确定values在您将其传递给 ArrayAdapter 时不为空构造函数?就在这条线的下方

  //Log.i("User Name",uname);

在构造函数调用之上,添加如下内容:
  Log.i("FriendsActivity", "values = <<" + values + ">>");

看看它是否真的是它应该是的。

关于java.lang.class - java.lang.RuntimeException : Unable to start activity ComponentInfo: java. lang.NullPointerException: storage == null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16777829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com