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"
00
相似问题