gpt4 book ai didi

android - 当我运行该程序时,我会遇到运行时问题

转载 作者:行者123 更新时间:2023-12-02 00:55:35 26 4
gpt4 key购买 nike

public class MainActivity extends AppCompatActivity {

Spinner basic_command;
String basic_cmd_buff[]= null;

Button button;

ArrayAdapter<String> adapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

basic_command = (Spinner) findViewById(R.id.basic_command);


basic_cmd_buff = new String[]
{
"WOPEN","CSQ","CREG","CGREG?","IPCONNECT"
};

adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,basic_cmd_buff);
basic_command.setAdapter(adapter);
}

public void back(View view)
{
finish();
}



}

这是错误日志:

02-02 13:57:26.562 27179-27179/com.example.sunbeam.test_application E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.sunbeam.test_application, PID: 27179 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sunbeam.test_application/com.example.sunbeam.test_application.MainActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) 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) Caused by: java.lang.NullPointerException at com.example.sunbeam.test_application.MainActivity.onCreate(MainActivity.java:38) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)  at android.app.ActivityThread.access$800(ActivityThread.java:135)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)  at android.os.Handler.dispatchMessage(Handler.java:102)  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) 

最佳答案

崩溃报告告诉您框架无法启动您的 Activity,然后告诉您原因。之后

Caused by:

在您的崩溃报告中,在 MainActivity.java 的第 38 行有一个 NullPointerException。

这大概是这条线造成的,

basic_command.setAdapter(adapter);

其中 basic_command 为空,因为

findViewById(R.id.basic_command);

如果找不到具有给定 ID 的 View ,则返回 null。检查您的 XML 布局文件是否正确。

关于android - 当我运行该程序时,我会遇到运行时问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54496671/

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