解决方案 »
- 往RelativeLayout动态加入ImageView的问题
- 请问android如何实现模式对话框 ?
- 如何在一个普通的View中得到输入的中文
- cursor提取数据时报错
- 使用Intent 在一个Activity中启动另一个Activity 异常终止这是为什么啊??错误信息如下
- 需要用到什么技术来实现这个实时画图程序?
- 有没有办法动态设置应用图标?
- android中锁屏状态下来短信,弹出一个能显示短信的界面
- Android 视频录制MediaRecorder相关问题,怎么生成缩略图?
- 执行了startActivity后,在此Activity还未显示的时候,怎么取消此界面的显示
- android如何实现带图标的list?
- 请教大家~android画图问题
1. ResolveData.broken_line_List.size(),看看返回值是多少。我估计是0.
2. 如果第一步返回值不是零,请检查ResolveData.broken_line_List.get(i),进入函数内被去检查一下。如果能将代码再贴上是最好的。
以下两个类都放在了ResolveData类中了。
public class ResolveData { //本类为省略的,我只拿出了主要内容。
public static List<Broken_line> broken_line_List = new ArrayList<Broken_line>();
broken_line(byte*,int *); //调用broken_line方法,并且多次调用broken_line方法,所以用broken_line_List来添加对象broken。
public static int broken_line(byte[] c,int j) {
System.out.println("以下线的数据");
Broken_line broken = new Broken_line();
broken.broken_point_number = c[j++];
for(int s = 0; s<broken.broken_point_number; s++){
broken.broken_x[s] = c[j++];
System.out.println(broken.broken_x[s]);
broken.broken_y[s] = c[j++];
System.out.println(broken.broken_y[s]);
}
broken_line_List.add(broken);
return j;
}
class Broken_line{ //这个类没有省略,是我程序中的原样
public byte broken_point_number;
public byte broken_x[] = new byte[5000];
public byte broken_y[] = new byte[5000];
public Broken_line(){
}
}
以下两个类都放在了ResolveData类中了。
public class ResolveData { //本类为省略的,我只拿出了主要内容。
public static List<Broken_line> broken_line_List = new ArrayList<Broken_line>();
broken_line(byte*,int *); //调用broken_line方法,并且多次调用broken_line方法,所以用 broken_line_List来添加对象broken。
public static int broken_line(byte[] c,int j) {
System.out.println("以下线的数据");
Broken_line broken = new Broken_line();
broken.broken_point_number = c[j++];
for(int s = 0; s<broken.broken_point_number; s++){
broken.broken_x[s] = c[j++];
System.out.println(broken.broken_x[s]);
broken.broken_y[s] = c[j++];
System.out.println(broken.broken_y[s]);
} broken_line_List.add(broken);
return j;
}
class Broken_line{ //这个类没有省略,是我程序中的原样
public byte broken_point_number;
public byte broken_x[] = new byte[5000];
public byte broken_y[] = new byte[5000];
public Broken_line(){}
}
public class ResolveData { //本类为省略的,我只拿出了主要内容。
public static List<Broken_line> broken_line_List = new ArrayList<Broken_line>();
broken_line(byte*,int *); //调用broken_line方法,并且多次调用broken_line方法,所以用 broken_line_List来添加对象broken。
public static int broken_line(byte[] c,int j) {
System.out.println("以下线的数据");
Broken_line broken = new Broken_line();
broken.broken_point_number = c[j++];
for(int s = 0; s<broken.broken_point_number; s++){
broken.broken_x[s] = c[j++];
System.out.println(broken.broken_x[s]);
broken.broken_y[s] = c[j++];
System.out.println(broken.broken_y[s]);
} broken_line_List.add(broken);
return j;
}
class Broken_line{ //这个类没有省略,是我程序中的原样
public byte broken_point_number;
public byte broken_x[] = new byte[5000];
public byte broken_y[] = new byte[5000];
public Broken_line(){}
}
public ResolveData getInstance(){
if(mResolveData==null){
mResolveData = new ResolveData();
}
return mResolveData;
}
通过ResolveData.getInstance().broken_line_List.get(i)来调用。
解决方法二:
public class MapView extends Activity {private ResolveData mResolveData;
public void onCreate(Bundle savedInstanceState) {
。
mResolveData = new ResolveData();
}以后调用的时候,用mResolveData.broken_line_List.get(i)就OK了。
以下两个类都放在了ResolveData类中了。
public class ResolveData { //本类为省略的,我只拿出了主要内容。
public static List<Broken_line> broken_line_List = new ArrayList<Broken_line>();
public ResolveData(){
.......
这个类中有多次的循环来保存数据的
broken_line(byte*,int *); //调用broken_line方法,并且多次调用broken_line方法
.........
}
public static int broken_line(byte[] c,int j) {
System.out.println("以下线的数据");
Broken_line broken = new Broken_line();
broken.broken_point_number = c[j++];
for(int s = 0; s<broken.broken_point_number; s++){
broken.broken_x[s] = c[j++];
System.out.println(broken.broken_x[s]);
broken.broken_y[s] = c[j++];
System.out.println(broken.broken_y[s]);
} broken_line_List.add(broken);
return j;
}
class Broken_line{ //这个类没有省略,是我程序中的原样
public byte broken_point_number;
public byte broken_x[] = new byte[5000];
public byte broken_y[] = new byte[5000];
public Broken_line(){}
}
以下两个类都放在了ResolveData类中了。
public class ResolveData { //本类为省略的,我只拿出了主要内容。
public static List<Broken_line> broken_line_List = new ArrayList<Broken_line>();
public ResolveData(){
.......
这个类中有多次的循环来保存数据的
broken_line(byte*,int *); //调用broken_line方法,并且多次调用broken_line方法
.........
}
public static int broken_line(byte[] c,int j) {
System.out.println("以下线的数据");
Broken_line broken = new Broken_line();
broken.broken_point_number = c[j++];
for(int s = 0; s<broken.broken_point_number; s++){
broken.broken_x[s] = c[j++];
System.out.println(broken.broken_x[s]);
broken.broken_y[s] = c[j++];
System.out.println(broken.broken_y[s]);
} broken_line_List.add(broken);
return j;
}
class Broken_line{ //这个类没有省略,是我程序中的原样
public byte broken_point_number;
public byte broken_x[] = new byte[5000];
public byte broken_y[] = new byte[5000];
public Broken_line(){}
}
额, 看了你的构造函数,我想说的是,ResolveData这个类的对象不是静态的,所以即使是类中的变量时静态你也是无法通过静态的方法来调用的。除非你将ResolveData类的对象设置为静态的,或者在new的时候保存这个类的对象,你才可以正常的使用。解决方法,依然是我刚才说的第一种。请确认在调用其他类的函数一定要确认,类的对象是否是正确的。从你给的代码中可以看出,红色部分的代码ResolveData使用的临时变量,而不是一开始你new的那个,解决方法如我刚才说的第二种。
以下红色标记是按您的第二中方法做的,但还是不执行那个For循环即mResolveData.broken_line_List.size()=0。public class MapView extends Activity { private static final String tag = null;
private ResolveData mResolveData;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResolveData = new ResolveData();
setContentView(new Map(this));
}
class Map extends View{
public Map(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int j = 0;
Paint paint=new Paint();
Style style=Style.FILL_AND_STROKE;
paint.setStyle(style);
paint.setColor(Color.BLUE);
float[] a = {100l, 50l,200l, 50l,10l, 20l, 10l,50l};
for(int i = 0; i<mResolveData.broken_line_List.size();i++){
Log.e(tag,"BBBBBBBBBBBBBBBB");
Broken_line br= mResolveData.broken_line_List.get(i);
canvas.drawLine(100,200,10,30, paint);
for(int kk = 0 ; kk<br.broken_point_number;kk++){
canvas.drawLine(br.broken_x[kk]+128,br.broken_y[kk],br.broken_x[kk+1] +725,br.broken_y[kk+1],paint);
}
}
}
}
}
对不起我错了,都跑到了。我给你看下我的测试代码,你的代码我没有看全。
package com.android.test;import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;public class test extends Activity { private Button mButton;
private statictest mTest;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
mTest = new statictest(this);
setContentView(new TestView(this));
/* mButton = (Button)findViewById(R.id.button);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("test", "mTest.mBitmapList.size() " + mTest.mBitmapList.size());
}
});*/
}
class TestView extends LinearLayout{ public TestView(Context context) {
super(context);
Log.i("test", "TestView mTest.mBitmapList.size() " + mTest.mBitmapList.size());
// TODO Auto-generated constructor stub
}
@Override
protected void dispatchDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.dispatchDraw(canvas);
Log.i("test", "dispatchDraw mTest.mBitmapList.size() " + mTest.mBitmapList.size());
} @Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Log.i("test", "onDraw mTest.mBitmapList.size() " + mTest.mBitmapList.size());
}
}
}
package com.android.test;import java.util.ArrayList;
import java.util.List;import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
public class statictest{
public static List<Bitmap> mBitmapList = new ArrayList<Bitmap>();
private Context mContext;
public statictest(Context context){
mContext = context;
Bitmap b = ((BitmapDrawable)mContext.getResources().getDrawable(R.drawable.icon)).getBitmap();
for(int i = 0; i < 10; i++){
storeList(b);
}
}
public static void storeList(Bitmap b){
mBitmapList.add(b);
}
}
public class A {
public static void main(String args[]){
new ResolveData(); //为了初始化ResolveData类中的数据
for(int m = 0; m<ResolveData.broken_line_List.size();m++){
Broken_line line = ResolveData.broken_line_List.get(m);
for(int kk = 0 ; kk<line.broken_point_number;kk++){
System.out.println(line.broken_x[kk]);
System.out.println(line.broken_y[kk]);
}
}
}
}
非常感谢帮我跑程序,我也做了一个测试类如下:能够完全运行。而且我用的是类名.变量也一样好使,这是为什么呢?
public class A {
public static void main(String args[]){
new ResolveData(); //为了初始化ResolveData类中的数据
for(int m = 0; m<ResolveData.broken_line_List.size();m++){
Broken_line line = ResolveData.broken_line_List.get(m);
for(int kk = 0 ; kk<line.broken_point_number;kk++){
System.out.println(line.broken_x[kk]);
System.out.println(line.broken_y[kk]);
}
} }
}
我找到错误了,因为我在ResolveData类的初始化中使用了File file = new File("D:\\***");这句话没有放到Android工程文件下的assets文件夹下,所以就不能显示在模拟器中了。