0

我遇到了一个非常奇怪的错误,似乎根本没有任何意义。我有一个似乎只是在启动时崩溃的适配器。似乎几乎随机设法设置使用我的自定义 BaseAdapter 来填充自定义 GridView。我通过 AsyncTask 启动 Activity,因此 UI 线程没有超时,并且它在低端崩溃的频率似乎与在高端设备上的崩溃频率大致相同。根据 logcat,当我尝试从主 Activity 类获取数组时,应用程序崩溃。这是我的 logcat 输出:

07-04 21:42:19.270: E/AndroidRuntime(12963): FATAL EXCEPTION: main
07-04 21:42:19.270: E/AndroidRuntime(12963): java.lang.NullPointerException
07-04 21:42:19.270: E/AndroidRuntime(12963):    at my.package.name.CustomAdapter.getView(CustomAdapter.java:142)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.AbsListView.obtainView(AbsListView.java:2470)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.GridView.onMeasure(GridView.java:1026)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at my.package.name.MyCustomGridView.onMeasure(MyCustomGridView.java:52)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.View.measure(View.java:12815)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1399)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1047)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:585)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.View.measure(View.java:12815)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.View.measure(View.java:12815)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.View.measure(View.java:12815)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1399)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:690)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:583)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.View.measure(View.java:12815)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2106)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.View.measure(View.java:12815)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1068)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2452)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.os.Looper.loop(Looper.java:137)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at android.app.ActivityThread.main(ActivityThread.java:4493)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at java.lang.reflect.Method.invokeNative(Native Method)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at java.lang.reflect.Method.invoke(Method.java:511)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
07-04 21:42:19.270: E/AndroidRuntime(12963):    at dalvik.system.NativeStart.main(Native Method)

我的 CustomAdapter 中的 getView:

public View getView (int position, View convertView, ViewGroup parent) {

mParentView = parent;

DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;


int box = width/7*6/10;

int boxH = height/7;

int gridS = width/7*6;

ImageCell v = null;
if (convertView == null) {
    // If it's not recycled, create a new ImageCell.
    v = new ImageCell (mContext);
    if(box*7>=height){
         v.setLayoutParams(new GridView.LayoutParams(boxH, boxH));
    }
    else{
    v.setLayoutParams(new GridView.LayoutParams(box, box));
    }
    v.setScaleType(ImageView.ScaleType.CENTER_CROP);
    v.setPadding(0, 0, 0, 0);


} else {
    v = (ImageCell) convertView;
}

v.mCellNumber = position;
v.mGrid = (GridView) mParentView;
v.mEmpty = true;
int id = 200;
v.setId(++id);

String map = str[position]; //line 142
int pos = position;
int up = pos-10;
int down = pos+10;
int left = pos-1;
int right = pos+1;

int le_up = pos-11;
int up_ri = pos-9;
int ri_do = pos+11;
int do_le = pos+9;

if(up>=0){
above = str[up];
}
else{
    above="l";

}
if(down<70){
    under = str[down];
    }
else{
    under="l";

}
if(left<=-1){

    lefte="l";
}

else{
     if(left==9|left==19|left==29|left==39|left==49|left==59){
        lefte="mountain";
    }
     else{
    lefte=str[left];
     }
}
if(right>=70){


    righte="l";
 }     
 else{
     if(right==10|right==20|right==30|right==40|right==50|right==60){
      righte="mountain";
    }
     else{
    righte=str[right];
     }
 }
if(le_up<=-1){
    left_up="l";
 }     
 else{
     if(le_up==9|le_up==19|le_up==29|le_up==39|le_up==49|le_up==59){
        left_up="mountain";
    }
     else{
     left_up=str[le_up];
     }
 }
if(up_ri<=-1){
    up_right="l";
}     
else{
     if(up_ri==10|up_ri==20|up_ri==30|up_ri==40|up_ri==50|up_ri==60){
        up_right="mountain";
    }
     else{
 up_right=str[up_ri];
     }
}
if(ri_do<70){
     if(ri_do==10|ri_do==20|ri_do==30|ri_do==40|ri_do==50|ri_do==60){
     right_down="mountain";
    }
     else{
    right_down = str[ri_do];
     }
    }
else{

    right_down="l";

}
if(do_le<70){
     if(do_le==9|do_le==19|do_le==29|do_le==39|do_le==49|do_le==59){
        down_left="mountain";
        }
     else{
    down_left = str[do_le];
     }
    }
else{

    down_left="l";

}



if (map.equals("mountain")) {
    //Checks surroundings to find out which drawable to set  
    v.setBackgroundResource(R.drawable.grass);
     v.mEmpty = false;
     //All
     if(above=="mountain"&&under=="mountain"&&lefte=="mountain"&&righte=="mountain"){
         //All edges
         if(left_up!="mountain"&&up_right!="mountain"&&right_down!="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_edges);
         }
         //One edge
         else if(left_up!="mountain"&&up_right=="mountain"&&right_down=="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_edge);
         }
         else if(left_up=="mountain"&&up_right!="mountain"&&right_down=="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_edge);
         }
         else if(left_up=="mountain"&&up_right=="mountain"&&right_down!="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_right_down_edge);
         }
         else if(left_up=="mountain"&&up_right=="mountain"&&right_down=="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_down_left_edge);
         }
         //Two edges
         else if(left_up!="mountain"&&up_right!="mountain"&&right_down=="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_right_edge);
         }
         else if(left_up!="mountain"&&up_right=="mountain"&&right_down!="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_right_down_edge);
         }
         else if(left_up!="mountain"&&up_right=="mountain"&&right_down=="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_down_left_edge);
         }
         else if(left_up=="mountain"&&up_right!="mountain"&&right_down!="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_down_edge);
         }
         else if(left_up=="mountain"&&up_right!="mountain"&&right_down=="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_down_left_edge);
         }
         else if(left_up=="mountain"&&up_right=="mountain"&&right_down!="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_right_down_left_edge);
         }
         //Tree edges
         else if(left_up=="mountain"&&up_right!="mountain"&&right_down!="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_down_left_edger);
         }
         else if(left_up!="mountain"&&up_right=="mountain"&&right_down!="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_right_down_left_up_edge);
         }
         else if(left_up!="mountain"&&up_right!="mountain"&&right_down=="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_down_left_up_right_edge);
         }
         else if(left_up!="mountain"&&up_right!="mountain"&&right_down!="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_right_down_edger);
         }
         else {
            v.setImageResource(R.drawable.grass);
         }
        }
     //Single
     else if(above=="mountain"&&under!="mountain"&&lefte!="mountain"&&righte!="mountain"){
            v.setImageResource(R.drawable.mountain_down);
        }
     else if(above!="mountain"&&under=="mountain"&&lefte!="mountain"&&righte!="mountain"){
            v.setImageResource(R.drawable.mountain_up);
        }
     else if(above!="mountain"&&under!="mountain"&&lefte!="mountain"&&righte=="mountain"){
            v.setImageResource(R.drawable.mountain_left);
        }
     else if(above!="mountain"&&under!="mountain"&&lefte=="mountain"&&righte!="mountain"){
            v.setImageResource(R.drawable.mountain_right);
        }
     //Double
     else if(above=="mountain"&&under!="mountain"&&lefte!="mountain"&&righte=="mountain"){
         if(up_right!="mountain"){
             v.setImageResource(R.drawable.mountain_left_down_edge);
         }
         else{
            v.setImageResource(R.drawable.mountain_left_down);
         }

        }
     else if(above!="mountain"&&under=="mountain"&&lefte!="mountain"&&righte=="mountain"){
         if(right_down!="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_edger);
         }
         else{       
            v.setImageResource(R.drawable.mountain_left_up);
         }
        }
     else if(above=="mountain"&&under!="mountain"&&lefte=="mountain"&&righte!="mountain"){
         if(left_up!="mountain"){
             v.setImageResource(R.drawable.mountain_right_down_edger);
         }
         else{       
             v.setImageResource(R.drawable.mountain_right_down);
         }          
        }
     else if(above!="mountain"&&under=="mountain"&&lefte=="mountain"&&righte!="mountain"){
         if(down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_edger);
         }
         else{       
             v.setImageResource(R.drawable.mountain_up_right);
         }      
        }
     else if(above!="mountain"&&under!="mountain"&&lefte=="mountain"&&righte=="mountain"){
            v.setImageResource(R.drawable.mountain_up_down);
        }
     else if(above=="mountain"&&under=="mountain"&&lefte!="mountain"&&righte!="mountain"){
            v.setImageResource(R.drawable.mountain_left_right);
        }
     //Triple
     else if(above!="mountain"&&under=="mountain"&&lefte=="mountain"&&righte=="mountain"){
         if(down_left!="mountain"&&right_down!="mountain"){
             v.setImageResource(R.drawable.mountain_left_right_down_right_down_left_edge);
         }
         else if(down_left=="mountain"&&right_down!="mountain"){
             v.setImageResource(R.drawable.mountain_left_right_down_right_down_edge);
         }
         else if(down_left!="mountain"&&right_down=="mountain"){
             v.setImageResource(R.drawable.mountain_left_right_down_down_left_edge);
         }
         else{       
             v.setImageResource(R.drawable.mountain_left_right_down);
         }      
        }
     else if(above=="mountain"&&under=="mountain"&&lefte=="mountain"&&righte!="mountain"){
         if(left_up!="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_down_left_up_edger);
         }
         else if(left_up=="mountain"&&down_left!="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_down_left_edger);
         }
         else if(left_up!="mountain"&&down_left=="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_down_left_up_edge);
         }
         else{       
             v.setImageResource(R.drawable.mountain_left_up_down);
         }                      
        }
     else if(above=="mountain"&&under!="mountain"&&lefte=="mountain"&&righte=="mountain"){
         if(left_up!="mountain"&&up_right!="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_right_left_up_right_edge);
         }
         else if(left_up=="mountain"&&up_right!="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_right_up_right_edge);
         }
         else if(left_up!="mountain"&&up_right=="mountain"){
             v.setImageResource(R.drawable.mountain_left_up_right_left_up_edge);
         }
         else{       
             v.setImageResource(R.drawable.mountain_left_up_right);
         }               

        }
     else if(above=="mountain"&&under=="mountain"&&lefte!="mountain"&&righte=="mountain"){
         if(up_right!="mountain"&&right_down!="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_down_up_right_down_edge);
         }
         else if(up_right=="mountain"&&right_down!="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_down_right_down_edge);
         }
         else if(up_right!="mountain"&&right_down=="mountain"){
             v.setImageResource(R.drawable.mountain_up_right_down_up_right_edge);
         }
         else{       
             v.setImageResource(R.drawable.mountain_up_right_down);
         }                  
        }
     //None
        else{
    v.setImageResource(R.drawable.mountain);
        }

}

else if(map=="stop"){
    v.mEmpty=false;
    v.setBackgroundResource(R.drawable.grass);
    v.setImageResource(R.drawable.oil_tank);
    v.setTag(1);
}
else if(map=="rock"){
    v.mEmpty=false;
    v.mBlowable=true;
    v.setBackgroundResource(R.drawable.grass);  
    v.setImageResource(R.drawable.rock);    

}
else if(map=="house"){
    v.mEmpty=false;
    v.mBulldozable=true;
    if(righte=="house"){
    v.setImageResource(R.drawable.dobble_house_left);   
    }
    else if(lefte=="house"){
    v.setImageResource(R.drawable.dobble_house_right);  
    }
    else{
    v.setImageResource(R.drawable.single_house);
    }
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="norhouse"){
    v.mEmpty=false;
    v.setBackgroundResource(R.drawable.grass);
    v.setImageResource(R.drawable.norhouse);
}
else if(map=="gold_pipe_left_right"){
    v.mEmpty=false;
    v.setTag(7913);
    v.setImageResource(R.drawable.left_right_gold_pipe_empty);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="gold_pipe_up_down"){
    v.mEmpty=false;
    v.setTag(7924);
    v.setImageResource(R.drawable.up_down_gold_pipe_empty);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="gold_pipe_left_up"){
    v.mEmpty=false;
    v.setTag(7912);
    v.setImageResource(R.drawable.left_up_gold_pipe_empty);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="gold_pipe_right_down"){
    v.mEmpty=false;
    v.setTag(7934);
    v.setImageResource(R.drawable.right_down_gold_pipe_empty);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="gold_pipe_up_right"){
    v.mEmpty=false;
    v.setTag(7923);
    v.setImageResource(R.drawable.up_right_gold_pipe_empty);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="gold_pipe_left_down"){
    v.mEmpty=false;
    v.setTag(7914);
    v.setImageResource(R.drawable.left_down_gold_pipe_empty);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="environmentalists"){
    v.mEmpty=false;
    v.mBribeable=true;
    v.setImageResource(R.drawable.environmentalists);
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="path"){
    v.mEmpty=true;
    //Full
    if(above=="path"&&under=="path"&&lefte=="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_cross);         
    }
    //Single
    else if(above!="path"&&under=="path"&&lefte!="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_up);  
    }
    else if(above=="path"&&under!="path"&&lefte!="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_down);  
    }
    else if(above!="path"&&under!="path"&&lefte=="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_right);  
    }
    else if(above!="path"&&under!="path"&&lefte!="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_left);  
    }
    //Double
    else if(above!="path"&&under!="path"&&lefte=="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_left_right);  
    }
    else if(above=="path"&&under=="path"&&lefte!="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_up_down);  
    }
    else if(above=="path"&&under!="path"&&lefte=="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_left_up);  
    }
    else if(above!="path"&&under=="path"&&lefte=="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_left_down);  
    }
    else if(above=="path"&&under!="path"&&lefte!="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_up_right);  
    }
    else if(above!="path"&&under=="path"&&lefte!="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_right_down);  
    }
    //Triple
    else if(above=="path"&&under!="path"&&lefte=="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_left_up_right);  
    }
    else if(above=="path"&&under=="path"&&lefte!="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_up_right_down);  
    }
    else if(above!="path"&&under=="path"&&lefte=="path"&&righte=="path"){
        v.setBackgroundResource(R.drawable.path_left_right_down);  
    }
    else if(above=="path"&&under=="path"&&lefte=="path"&&righte!="path"){
        v.setBackgroundResource(R.drawable.path_left_up_down);  
    }
    else{
    v.setBackgroundResource(R.drawable.path);
    }
}

else if(map=="tree"){
    v.mEmpty=false;
    v.mCutable=true;
    if(righte=="tree"){
    v.setImageResource(R.drawable.small_leaf_tree_left);    
    }
    else if(lefte=="tree"){
    v.setImageResource(R.drawable.small_leaf_tree_right);   
    }
    else{
    v.setImageResource(R.drawable.small_leaf_tree);
    }
    v.setBackgroundResource(R.drawable.grass);
}
else if(map=="water"){
    v.mEmpty=false;
    v.mBridgeable = true;
     v.setBackgroundResource(R.drawable.grass);
    //All
     if(above=="water"&&under=="water"&&lefte=="water"&&righte=="water"){
         //All edges
         if(left_up!="water"&&up_right!="water"&&right_down!="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_edges);
         }
         //One edge
         else if(left_up!="water"&&up_right=="water"&&right_down=="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_left_up_c);
         }

         else if(left_up=="water"&&up_right!="water"&&right_down=="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_up_right_c);
         }
         else if(left_up=="water"&&up_right=="water"&&right_down!="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_right_down_c);
         }
         else if(left_up=="water"&&up_right=="water"&&right_down=="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_down_left_c);
         }

         //Two edges
         else if(left_up!="water"&&up_right!="water"&&right_down=="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_left_up_right_c);
         }
         else if(left_up!="water"&&up_right=="water"&&right_down!="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_left_up_right_down_c);
         }
         else if(left_up!="water"&&up_right=="water"&&right_down=="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_down_left_up);
         }
         else if(left_up=="water"&&up_right!="water"&&right_down!="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_up_right_down_c);
         }
         else if(left_up=="water"&&up_right!="water"&&right_down=="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_up_right_down_left_c);
         }
         else if(left_up=="water"&&up_right=="water"&&right_down!="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_right_down_left);
         }

         //Tree edges
         else if(left_up=="water"&&up_right!="water"&&right_down!="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_up_right_down_left);
         }
         else if(left_up!="water"&&up_right=="water"&&right_down!="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_right_down_left_up);
         }
         else if(left_up!="water"&&up_right!="water"&&right_down=="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_down_left_up_right);
         }
         else if(left_up!="water"&&up_right!="water"&&right_down!="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_left_up_right_down);
         }


        }

     //Single
     else if(above=="water"&&under!="water"&&lefte!="water"&&righte!="water"){
            v.setImageResource(R.drawable.water_down);
        }
     else if(above!="water"&&under=="water"&&lefte!="water"&&righte!="water"){
            v.setImageResource(R.drawable.water_up);
        }
     else if(above!="water"&&under!="water"&&lefte!="water"&&righte=="water"){
            v.setImageResource(R.drawable.water_left);
        }
     else if(above!="water"&&under!="water"&&lefte=="water"&&righte!="water"){
            v.setImageResource(R.drawable.water_right);

     }



     //Double
     else if(above=="water"&&under!="water"&&lefte!="water"&&righte=="water"){
         if(up_right!="water"){
             v.setImageResource(R.drawable.water_left_down_up_right_csa);
         }
         else{
            v.setImageResource(R.drawable.water_left_down);
         }

        }
     else if(above!="water"&&under=="water"&&lefte!="water"&&righte=="water"){
         if(right_down!="water"){
             v.setImageResource(R.drawable.water_left_up_right_down_csa);
         }
         else{       
            v.setImageResource(R.drawable.water_left_up);
         }
        }
     else if(above=="water"&&under!="water"&&lefte=="water"&&righte!="water"){
         if(left_up!="water"){
             v.setImageResource(R.drawable.water_right_down_left_up_csa);
         }
         else{       
             v.setImageResource(R.drawable.water_right_down);
         }          
        }
     else if(above!="water"&&under=="water"&&lefte=="water"&&righte!="water"){
         if(down_left!="water"){
             v.setImageResource(R.drawable.water_up_right_down_left_csa);
         }
         else{       
             v.setImageResource(R.drawable.water_up_right);
         }      
        }
     else if(above!="water"&&under!="water"&&lefte=="water"&&righte=="water"){
            v.setImageResource(R.drawable.water_up_down);
        }
     else if(above=="water"&&under=="water"&&lefte!="water"&&righte!="water"){
            v.setImageResource(R.drawable.water_left_right);

        }

     //Triple
     else if(above!="water"&&under=="water"&&lefte=="water"&&righte=="water"){
         if(down_left!="water"&&right_down!="water"){
             v.setImageResource(R.drawable.water_up_right_down_left_cs);
         }
         else if(down_left=="water"&&right_down!="water"){
             v.setImageResource(R.drawable.water_up_right_down_cs);
         }
         else if(down_left!="water"&&right_down=="water"){
             v.setImageResource(R.drawable.water_up_down_left_cs);
         }
         else{       
             v.setImageResource(R.drawable.water_left_right_down);
         }      
        }

     else if(above=="water"&&under=="water"&&lefte=="water"&&righte!="water"){
         if(left_up!="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_right_left_up_down_left_cs);
         }
         else if(left_up=="water"&&down_left!="water"){
             v.setImageResource(R.drawable.water_right_down_left_cs);
         }
         else if(left_up!="water"&&down_left=="water"){
             v.setImageResource(R.drawable.water_right_left_up_cs);
         }
         else{       
             v.setImageResource(R.drawable.water_left_up_down);
         }                      
        }

     else if(above=="water"&&under!="water"&&lefte=="water"&&righte=="water"){
         if(left_up!="water"&&up_right!="water"){
             v.setImageResource(R.drawable.water_down_left_up_right_cs);
         }
         else if(left_up=="water"&&up_right!="water"){
             v.setImageResource(R.drawable.water_down_up_right_cs);
         }
         else if(left_up!="water"&&up_right=="water"){
             v.setImageResource(R.drawable.water_down_left_up_cs);
         }
         else{       
             v.setImageResource(R.drawable.water_left_up_right);
         }               

        }

     else if(above=="water"&&under=="water"&&lefte!="water"&&righte=="water"){
         if(up_right!="water"&&right_down!="water"){
             v.setImageResource(R.drawable.water_left_up_right_down_cs);
         }
         else if(up_right=="water"&&right_down!="water"){
             v.setImageResource(R.drawable.water_left_right_down_cs);
         }
         else if(up_right!="water"&&right_down=="water"){
             v.setImageResource(R.drawable.water_left_up_right_cs);
         }
         else{       
             v.setImageResource(R.drawable.water_up_right_down);
         }  

     }
     //None
        else{
    v.setImageResource(R.drawable.water_full);
        }



}
else if(map=="start"){

    v.setTag(2);
    List<String> posOf = Arrays.asList(str);
    startPos=posOf.indexOf("start");
    curPipe=startPos;
    v.mEmpty=false;
    v.setBackgroundResource(R.drawable.grass);
    grid = GameProjectActivity.gridView;
    final ImageCell over =(ImageCell)grid.getChildAt(startPos-10);
    over.mEmpty=false;
    getDur();

     //Had to remove some imports to lower number of characters

     int delay=GameProjectActivity.startDelay;  
     final int signalDelay=delay-3500;

     AnimationDrawable loop = new AnimationDrawable(); 
     loop.addFrame(first, duration);
     loop.addFrame(first, duration);
     loop.addFrame(first, duration);
     loop.setOneShot(false);

    final AnimationDrawable ani = new AnimationDrawable(); 
       ani.addFrame(first, delay);
       ani.addFrame(first, duration);
       ani.addFrame(second, duration);
       ani.addFrame(third, duration);
       ani.addFrame(fourth, duration);

       ani.setOneShot(true);
     v.setImageDrawable(ani);        
       checkIfAnimationDone(ani); 
    v.post(new Runnable() {   
        public void run() {
               ani.start();
                }
        });
    final AnimationDrawable anima = new AnimationDrawable();       
    anima.addFrame(frame2, 200);
    anima.addFrame(frame3, 200);
    anima.addFrame(frame4, 200);
    anima.addFrame(frame5, 200);
    anima.addFrame(frame6, 200);
    anima.addFrame(frame7, 150);
    anima.addFrame(frame8, 150);
    anima.addFrame(frame1, 500);

    anima.setOneShot(false);

    over.setImageResource(R.drawable.oil_tower_top);
    Handler handler = new Handler();

         handler.postDelayed(new Runnable() {
        public void run() {
            over.setImageDrawable(anima);
               anima.start();

                }
        },signalDelay);

}


return v;

}

如果我需要从我的项目中发布更多代码,请通知我!编辑:我的大部分代码没有意义,但它是关卡生成系统的一部分。

4

0 回答 0