0

Can't run my little Android code in Eclipse, I get this error message:

E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity 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. I do import java.lang.math.* Why does it say it's a "nullpointer"? The editor doesn't mark my math functions with any error. I suppose this is some obscure path problem with Eclipse.

Project/properties/Order and Export only lists: - 2Dto3D/src (2Dto3D is my project name) - 2Dto3D/gen - Android 4.2 - Android Dependencies

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

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;

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.*;

public class MainActivity extends 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

Tombola
  • 1,131
  • 5
  • 15
  • 26
  • 2
    Does the stack trace include a line number within your code? Post that code. (It's almost certainly simply a bug in your code - that *is* started, but doesn't get as far as showing your activity. However, we can't really help you without seeing any code.) It's not clear why you're focusing on the `java.lang.math.*` side of things, which is almost certainly irrelevant... – Jon Skeet Feb 05 '13 at 14:09
  • Need to post code and stacktrace from the logcat output. Nobody can help you without it – Boardy Feb 05 '13 at 14:14
  • Just post your activity. – Sotirios Delimanolis Feb 05 '13 at 14:17
  • This is a null pointer exception, a runtime error typically caused by trying to call a method/access a field of an object which is null - often as it has not be successfully initialized. Since the error occurs only at runtime it will not be caught by the compiler. You'll need to take the line number from the full stack trace and figure out what could be un-executable about that line of code at runtime. – Chris Stratton Feb 05 '13 at 14:21
  • The full stack trace is as important as the activity code. – Chris Stratton Feb 05 '13 at 14:23

2 Answers2

3

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

gCQ = new double[size];

Same goes for both your double[] and String[]

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • Yes as simple as that! Stupid me forgot about array syntax. I wish the error message could've reminded me about that. – Tombola Feb 05 '13 at 15:40
0

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.

Not sure if this works but here is a link to something similar: Can the Android SDK work with JDK 1.7?

Community
  • 1
  • 1
jelgh
  • 705
  • 1
  • 6
  • 22