我被困住了。我已经花了几个小时看这个,我知道这一定是我做错了一些微不足道的事情。我的母语“语言”是 C++,但我想使用 Android。我真的很喜欢在 C++ 中使用结构,但发现我必须使用 Java 中的类来解决问题。由于我的课程有问题,我已经很好地缩小了我得到一个空指针的范围。有任何想法吗?
这是标有第 267 行的代码:
public class Vectors extends Activity{
Button next;
public class infoC{
double value = 0, angle = 0;
boolean radian = false; //radians/degrees
int quad = 1; //Quadrant
}
public infoC[] info;
int counter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.vectors);
vectorsView = new VectorsView(this);
l = (LinearLayout) findViewById(R.id.llCanvasV);
l.addView(vectorsView);
Initialize();
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
error.setText("");
if(value.getText().toString().length()==0||value.getText()==null||angle.getText().toString().length()==0||angle.getText()==null)
error.setText("Must enter both value and angle");
else{
Log.e("Counter", Integer.toString(counter));
Log.e("Value", value.getText().toString());
storeInfo(); //121
counter++;
}
}
});
}
public void storeInfo(){
Doublify(value);
Doublify(angle);
String temp;
temp=value.getText().toString();
info[counter].value = Double.parseDouble(temp);//267, Inserted temp instead of getText.toString
info[counter].angle = Double.parseDouble(angle.getText().toString());
info[counter].radian = rad.isChecked();
if(q1.isChecked())
info[counter].quad=1;
if(q2.isChecked())
info[counter].quad=2;
if(q3.isChecked())
info[counter].quad=3;
if(q4.isChecked())
info[counter].quad=4;
angle.setText("");
value.setText("");
}
}
这是日志猫:
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): FATAL EXCEPTION: main
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): java.lang.NullPointerException
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at com.prattia.webs.cheaterphysics.Vectors.storeInfo(Vectors.java:267)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at com.prattia.webs.cheaterphysics.Vectors$7.onClick(Vectors.java:121)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at android.view.View.performClick(View.java:2465)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at android.view.View$PerformClick.run(View.java:8907)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at android.os.Handler.handleCallback(Handler.java:587)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at android.os.Handler.dispatchMessage(Handler.java:92)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at android.os.Looper.loop(Looper.java:123)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at java.lang.reflect.Method.invoke(Method.java:521)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-13 18:50:45.188: ERROR/AndroidRuntime(9892): at dalvik.system.NativeStart.main(Native Method)