getApplication()报空指针

来源:3-3 基础框架可用性验证

AnnaKing86

2017-11-24

public class MainActivity extends AppCompatActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       Toast.makeText(Leo.getApplication(), "传入context啦啦啦", Toast.LENGTH_SHORT).show();
   }
}

 Caused by: java.lang.NullPointerException
                                                                       at android.widget.Toast.<init>(Toast.java:93)
                                                                       at android.widget.Toast.makeText(Toast.java:241)
                                                                       at com.ustc.notehelper.MainActivity.onCreate(MainActivity.java:18)
                                                                       at android.app.Activity.performCreate(Activity.java:5231)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243) 
                                                                       at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)


写回答

1回答

AnnaKing86

提问者

2017-11-24

已经解决,配置文件少了android:name=".ExampleApp"

0
0

Android通用框架设计与完整电商App开发

从第一行代码开始教你,通用且一键式配置的框架设计并轻松实现完整电商App

2028 学习 · 1182 问题

查看课程