无法在Eclipse中运行我的Android小代码,我收到以下错误消息:
E/AndroidRuntime(275):java.lang.RuntimeException:无法启动活动ComponentInfo{com.mytest.threedee/com.mytest.Threede.MainActivity}:java.lang.NullPointerException
还有什么有用的信息?我想我的代码是不重要的,因为Eclipse甚至无法开始执行它。我确实导入java.lang.math。*为什么它说它是"nullpointer"?编辑器没有将我的数学函数标记为任何错误。我想这是Eclipse的一些模糊路径问题。
仅项目/属性/订单和导出列表:-2Dto3D/src(2Dto3D是我的项目名称)-2Dto3D/代-安卓4.2-安卓依赖
应该有更多的东西吗?
在source选项卡下,它显示"Native library location:(None)"。听起来很糟糕,不是吗?
我有: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;
}
}//结束主活动
您仍未初始化数组
double[] gCQ;
// later, you use it as is
gCQ[i] = i/3;
您应该在onCreate()
或外部进行初始化
gCQ = new double[size];
double[]
和String[]
也是如此
不确定你的崩溃是否是因为你有1.7,但我认为Android SDK只支持Jdk 1.6。
不确定这是否有效,但这里有一个类似的链接:Android SDK能否与JDK 1.7配合使用?