无法在 Eclipse 中运行我的小 Android 代码,我收到以下错误消息:
E/AndroidRuntime(275):java.lang.RuntimeException:无法启动活动 ComponentInfo{com.mytest.threedee/com.mytest.threedee.MainActivity}: java.lang.NullPointerException
还有哪些信息可能会有所帮助?我猜我的代码无关紧要,因为 Eclipse 甚至无法开始执行它。我确实 import java.lang.math.* 为什么说它是“空指针”?编辑器不会将我的数学函数标记为任何错误。我想这是 Eclipse 的一些模糊路径问题。
Project/properties/Order and Export 仅列出: - 2Dto3D/src(2Dto3D 是我的项目名称) - 2Dto3D/gen - Android 4.2 - Android Dependencies
那里可能还有更多东西吗?
在源选项卡下,它显示“本机库位置:(无)”。听起来很糟糕,不是吗?
我有: Windows 7、64 位 已经为移动开发人员下载了 java JDK 7、64 位 Eclipse Juno 版本 1 尝试在虚拟设备 API 8 上运行我的代码
还有我的代码(测试计算的开始):( 对不起,导入块不会进入代码格式这里)
包 com.mytest.threedee;
导入 com.mytest.threedee.R;导入android.app.Activity;导入android.os.Bundle;导入 android.view.Menu;导入 android.widget.TextView;导入静态 java.lang.Math.*;
公共类 MainActivity 扩展 Activity {
static final double pixPerRad = 4850;
static final double center2Dhor = 276.6;
static final double center2Dver = 293.7;
static final double short2D = 426.3;
static final double long2D = 2719.3;
static final double tilt2D = -0.2557;
double minor, major, MSC, CSL; // angles
double CM, MS, ML, CL; // distances
double gQJ, gVQ, gQL, gHL, gVL, gMLV, gCLQ; // temporary guessing variables
double[] gCQ, gmajor; // guessing variables whose guess values will be stored
String[] gmajor_Text;
String[] gCQ_Text;
TextView text1 = null;
TextView text2 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (TextView)findViewById(R.id.textView1);
text2 = (TextView)findViewById(R.id.textView2);
minor = short2D/pixPerRad;
major = long2D/pixPerRad;
MS = 1/asin(minor);
ML = MS;
CM = sqrt(MS*MS - 1);
CL = MS - ML;
// Guessing triangle VQJ:
for (int i=0; i<2; i++)
{
gCQ[i] = i/3; // First two guesses
// Side QJ:
gQJ = sqrt(1 - gCQ[i]*gCQ[i]);
// Side VQ:
gQL = sqrt(CL*CL + gCQ[i]*gCQ[i]);
gCLQ = asin(gCQ[i]/gQL);
gMLV = gCLQ;
gHL = ML*cos(gMLV);
gVL = 2*gHL;
gVQ = gVL - gQL;
// major angle resulting from guess:
gmajor[i] = 2 * atan(gQJ/gVQ);
gmajor_Text[i] = String.valueOf(gmajor);
gCQ_Text[i] = String.valueOf(gCQ);
}//END for i
text1.setText(gmajor_Text[0]);
text2.setText(gCQ_Text[1]);
}//END onCreate
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}//END MainActivity