Reputation: 31
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();
}
}
And this is the error log:
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)
Upvotes: 3
Views: 87
Reputation: 306
The crash report is telling you that the framework failed to launch your Activity, and then it is telling you why that is. After
Caused by:
in your crash report, there is a NullPointerException at line 38 in your MainActivity.java.
This is probably caused by this line,
basic_command.setAdapter(adapter);
where basic_command is null, because
findViewById(R.id.basic_command);
returns null when it can't find a View with the given ID. Check if your XML layout file is correct.
Upvotes: 2