无法在Eclipse中运行我的小Android代码,我收到此错误消息:
E / AndroidRuntime(275):java.lang.RuntimeException: 无法启动活动ComponentInfo {com.mytest.threedee / com.mytest.threedee.MainActivity}: 的显示java.lang.NullPointerException
还有什么信息可以提供帮助? 我想我的代码是无关紧要的,因为Eclipse甚至无法开始执行它。 我导入java.lang.math。*为什么它说它是“nullpointer”?编辑器没有标记我的数学函数有任何错误。我想这是Eclipse的一些模糊路径问题。
项目/属性/订单和导出仅列出: - 2Dto3D / src(2Dto3D是我的项目名称) - 2Dto3D / gen - Android 4.2 - Android依赖项
那里可能还有更多东西吗?
在源选项卡下,显示“本机库位置:(无)”。 听起来很糟糕,不是吗?
我有: Windows 7,64位 已下载java JDK 7,64位 Eclipse for Mobile Developers Juno发布1 尝试在虚拟设备API 8上运行我的代码
我的代码(测试计算的开始): (很抱歉导入块不会进入代码格式化)
包com.mytest.threedee;
import com.mytest.threedee.R; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.TextView; import static 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
答案 0 :(得分:3)
您仍然没有初始化数组
double[] gCQ;
// later, you use it as is
gCQ[i] = i/3;
您应该在onCreate()
或外部
gCQ = new double[size];
同样适用于double[]
和String[]
答案 1 :(得分:0)
不确定您的崩溃是否是由于您有1.7但我认为Android SDK仅支持Jdk 1.6。
不确定这是否有效,但这里是类似的链接: Can the Android SDK work with JDK 1.7?