我有一个具有以下方法的 GPSLoc 类
public class GPSLoc {
public static void HAHA ()
{
{Toast.makeText( context,"SD Card not available , savin to local phone", Toast.LENGTH_LONG).show();};
}
private static Context context;
然后我在主活动中创建一个按钮,简单的任务是调用该方法并显示吐司
Button three=(Button)findViewById(R.id.three);
three.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
GPSLoc Test1=new GPSLoc();
Test1.HAHA();
}
然后我在 LogCat 中得到了它
07-13 20:41:39.492: E/AndroidRuntime(6778): FATAL EXCEPTION: main
07-13 20:41:39.492: E/AndroidRuntime(6778): java.lang.NullPointerException
07-13 20:41:39.492: E/AndroidRuntime(6778): at android.widget.Toast.<init>(Toast.java:90)
07-13 20:41:39.492: E/AndroidRuntime(6778): at android.widget.Toast.makeText(Toast.java:232)
07-13 20:41:39.492: E/AndroidRuntime(6778): at com.example.testnewbutton.GPSLoc.HAHA(GPSLoc.java:100)
07-13 20:41:39.492: E/AndroidRuntime(6778): at com.example.testnewbutton.MainActivity$1.onClick(MainActivity.java:67)