Write an android dial and run the following error:
04-09 01:36:33. 880: E/AndroidRuntime (3689): Caused by: java. lang. NullPointerException
04-09 01:36:33. 880: E/AndroidRuntime (3689): at com. example. phone. MainActivity. onCreate (MainActivity. java: 30)
I haven't found any answers online for a long time.
The Code is as follows:
1 package com. example. phone;
2
3 import android. support. v7.app. ActionBarActivity;
4 import android. support. v7.app. ActionBar;
5 import android. support. v4.app. Fragment;
6 import android. text. TextUtils;
7 import android. content. Intent;
8 import android.net. Uri;
9 import android. OS. Bundle;
10 import android. view. LayoutInflater;
11 import android. view. Menu;
12 import android. view. MenuItem;
13 import android. view. View;
14 import android. view. ViewGroup;
15 import android. view. View. OnClickListener;
16 import android. widget. Button;
17 import android. widget. EditText;
18 import android. widget. Toast;
19 import android. OS. Build;
20
21 public class MainActivity extends ActionBarActivity {
22 public EditText call_number;
23
24 @ Override
25 protected void onCreate (Bundle savedInstanceState ){
26 super. onCreate (savedInstanceState );
27 setContentView (R. layout. activity_main );
28 Button bt_call = (Button) findViewById (R. id. button );
29 call_number = (EditText) this. findViewById (R. id. et_number );
30
Bt_call.setOnClickListener (new mybuttonclick ());
31 if (savedInstanceState = null ){
32 getsuppfrfragmentmanager (). beginTransaction ()
33. add (R. id. container, new PlaceholderFragment (). commit ();
34}
35}
36
37 private class mybuttonclick implements OnClickListener {
38
39 @ Override
40 public void onClick (View v ){
41 String number = call_number.getText (). toString (). trim ();
42 if (TextUtils. isEmpty (number )){
43 Toast. makeText (MainActivity. this, "the number cannot be blank", Toast. LENGTH_SHORT)
44. show ();
45 return;
46}
47 Intent intent = new Intent ();
48 intent. setAction (Intent. ACTION_CALL );
49 intent. setData (Uri. parse ("tel:" + number ));
50 startActivity (intent );
51}
52
53}
54
55 /**
56 * A placeholder fragment containing a simple view.
57 */
58 public static class PlaceholderFragment extends Fragment {
59
60 public PlaceholderFragment (){
61}
62
63 @ Override
64 public View onCreateView (LayoutInflater inflater, ViewGroup container,
65 Bundle savedInstanceState ){
66 View rootView = inflater. inflate (R. layout. fragment_main, container,
67 false );
68 return rootView;
69}
70}
71
72}
The following error is reported during running.
04-09 01:36:33. 880: W/dalvikvm (3689): threadid = 1: thread exiting with uncaught exception (group = 0x40bcc300)
04-09 01:36:33. 880: E/AndroidRuntime (3689): fatal exception: main
01:36:33 04-09. 880: E/AndroidRuntime (3689): java. lang. runtimeException: Unable to start activity ComponentInfo {com. example. phone/com. example. phone. mainActivity}: java. lang. nullPointerException
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. ActivityThread. initialize mlaunchactivity (ActivityThread. java: 2110)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. ActivityThread. handleLaunchActivity (ActivityThread. java: 2135)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. ActivityThread. access $700 (ActivityThread. java: 131)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. ActivityThread $ H. handleMessage (ActivityThread. java: 1228)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. OS. Handler. dispatchMessage (Handler. java: 99)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. OS. Looper. loop (Looper. java: 137)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. ActivityThread. main (ActivityThread. java: 4866)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at java. lang. reflect. Method. invokeNative (Native Method)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at java. lang. reflect. Method. invoke (Method. java: 511)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at com. android. internal. OS. ZygoteInit $ MethodAndArgsCaller. run (ZygoteInit. java: 786)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at com. android. internal. OS. ZygoteInit. main (ZygoteInit. java: 553)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at dalvik. system. NativeStart. main (Native Method)
04-09 01:36:33. 880: E/AndroidRuntime (3689): Caused by: java. lang. NullPointerException
04-09 01:36:33. 880: E/AndroidRuntime (3689): at com. example. phone. MainActivity. onCreate (MainActivity. java: 30)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. Activity. Wait mcreate (Activity. java: 5143)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. Instrumentation. callActivityOnCreate (Instrumentation. java: 1079)
04-09 01:36:33. 880: E/AndroidRuntime (3689): at android. app. ActivityThread. initialize mlaunchactivity (ActivityThread. java: 2074)
04-09 01:36:33. 880: E/AndroidRuntime (3689):... 11 more