[英]Android java.lang.NullPointer. Wrong path Eclipse Juno - JDK7?
Can't run my little Android code in Eclipse, I get this error message: 无法在Eclipse中运行我的Android小代码,出现以下错误消息:
E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mytest.threedee/com.mytest.threedee.MainActivity}: java.lang.NullPointerException E / AndroidRuntime(275):java.lang.RuntimeException:无法启动活动ComponentInfo {com.mytest.threedee / com.mytest.threedee.MainActivity}: java.lang.NullPointerException
What more info could be helpful? 还有哪些其他信息可能会有所帮助? I guess my code is irrelevent because Eclipse fails to even start executing it.
我猜我的代码是无关紧要的,因为Eclipse甚至无法开始执行它。 I do import java.lang.math.* Why does it say it's a "nullpointer"?
我确实导入了java.lang.math。*为什么会说它是“空指针”? The editor doesn't mark my math functions with any error.
编辑器不会将我的数学函数标记为任何错误。 I suppose this is some obscure path problem with Eclipse.
我想这是Eclipse的一些晦涩的路径问题。
Project/properties/Order and Export only lists: - 2Dto3D/src (2Dto3D is my project name) - 2Dto3D/gen - Android 4.2 - Android Dependencies 项目/属性/仅订购和导出仅列出:-2Dto3D / src(2Dto3D是我的项目名称)-2Dto3D / gen-Android 4.2-Android依赖关系
Should there maybe be something more there? 可能还有其他东西吗?
Under source tab, it says "Native library location: (None)". 在“源”选项卡下,显示“本地库位置:(无)”。 Sounds bad, doesn't it?
听起来不好,不是吗?
I have: Windows 7, 64 bit Have downloaded java JDK 7, 64 bit Eclipse for Mobile Developers Juno release 1 Try to run my code on a virtual device API 8 我有:Windows 7、64位已下载Java JDK 7,面向移动开发人员的64位Eclipse Juno版本1尝试在虚拟设备API 8上运行我的代码
And my code (beginnings of a test calculation): (Sorry that the import block won't get into the code formatting here) 我的代码(测试计算的开头):(很抱歉,导入块不会进入此处的代码格式)
package com.mytest.threedee; 包com.mytest.threedee;
import com.mytest.threedee.R; 导入com.mytest.threedee.R; import android.app.Activity;
导入android.app.Activity; import android.os.Bundle;
导入android.os.Bundle; import android.view.Menu;
导入android.view.Menu; import android.widget.TextView;
导入android.widget.TextView; import static java.lang.Math.*;
导入静态java.lang.Math。*;
public class MainActivity extends Activity { 公共类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 } // END MainActivity
You still haven't initialized your arrays 您仍然没有初始化数组
double[] gCQ;
// later, you use it as is
gCQ[i] = i/3;
You should initialize either in the onCreate()
or outside 您应该在
onCreate()
或外部进行初始化
gCQ = new double[size];
Same goes for both your double[]
and String[]
double[]
和String[]
Not sure if your crash is due to that you have 1.7 but I thought that the Android SDK only supported Jdk 1.6. 不知道您的崩溃是否是由于您有1.7,但我认为Android SDK仅支持Jdk 1.6。
Not sure if this works but here is a link to something similar: Can the Android SDK work with JDK 1.7? 不确定是否可以使用,但是这里有类似链接: Android SDK是否可以与JDK 1.7一起使用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.