Domanda

I want convert value in Info_TimeD1[] from string array to long array and store in ohh[].I found error and I can't pass this case.

String[] Info_TimeD1;  
String[] ohh;
int i;

int L1 = Info_TimeD1.length;

    for(int i=0;i<L1;i++)
{
     Long Timestamp1[i] = Long.parseLong(Info_TimeD1[i]); // error this line
     ohh[i] = getDateCurrentTimeZone1(Timestamp1[i]);
}
È stato utile?

Soluzione 2

You have a few different issues,

String[] Info_TimeD1;
String[] ohh;
// int i; <-- Duplicate variable with your for loop.

int L1 = Info_TimeD1.length;
Long[] Timestamp1 = new Long[L1]; // <-- Declare your array.
for (int i = 0; i < L1; i++) {
    Timestamp1[i] = Long.parseLong(Info_TimeD1[i]); // <-- Fixed.
    ohh[i] = getDateCurrentTimeZone1(Timestamp1[i]);
}

Altri suggerimenti

This isn't valid Java:

Long Timestamp1[i] = // anything...

It's not really clear what you're trying to do - if you're trying to populate a single element of an existing array, you should use:

Timestamp1[i] = ...

If you're trying to declare a new variable, you should use:

long timestamp = ...

Currently your code is somewhere between the two.

As an aside, I would strongly advise you to start following Java naming conventions.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top