최근에 무선 센서 네트워크와 전화기를 통합하려는 시도에서 나는 활동으로뿐만 아니라 직렬 포트에서 읽고 청취자 클래스를 읽음으로써 단순한 캔버스 기반보기. 처음에는 좀 더 일반적인 메시지 처리기와 스레드를 사용하여 스레드 된 캔버스를 구성 해 보았습니다. 그러나 스레드를 업데이트하고 무효화하는 스레드가 있는데,이 스레드는 USB 포트를 수신하는 스레드에서 작동하고 있습니다. 나는 그 시간에 일할 수 없었고 나는 새로운 판독 값으로 업데이트하기 만하면 주어진 캔버스를 지속적으로 업데이트 할 필요가 없다고 결정했다.Null Pointer on View
그래서 활동 등급은 다음과 같습니다.
public class Oscilloscope extends Activity implements MessageListener
Graph graph;
boolean guard=false;
MoteIF mote;
Data data;
String comm;
static String writeLog;
public Vector <Integer> arrayvals = new Vector<Integer>();
public Oscilloscope(String comm, String writelog)
{
this.comm = comm;
this.writeLog = writelog;
}
public Oscilloscope()
{
}
public void onCreate(Bundle b)
{
super.onCreate(b);
graph = new Graph(this);
this.setContentView(graph);
if(guard==false)
{
create("dummy:1",null).run();
}
}
synchronized public void messageReceived(int dest_addr, Message msg) {
if (msg instanceof OscilloscopeMsg) {
OscilloscopeMsg omsg = (OscilloscopeMsg)msg;
periodUpdate(omsg.get_version(), omsg.get_interval());
data.update(omsg.get_id(), omsg.get_count(), omsg.get_readings());
List temp1 = Arrays.asList(omsg.get_readings());
Vector<Integer> temp= new Vector<Integer>(temp1);
this.arrayvals = temp;
Paint p = new Paint();
p.setColor(Color.BLUE);
this.graph.update();
this.graph.invalidate();
}
}
public Oscilloscope create(String a, String b)
{
guard = true;
Oscilloscope os = new Oscilloscope(a,b);
os.guard = true;
return os;
}
코드 괄호가 제대로 작동하지 않는 이유는 확실하지 않습니다. 사과드립니다. 클래스에는 다른 메소드가 있지만 클래스 자체는 뷰 부분을 제외하고, readings가 int 배열로 읽혀진 messagereceived 메소드에 특히주의를 기울여 동작합니다. 내 문제는 한 번 onDraw 메서드를 한 번 호출 한 다음 messagereceived 나중에 그래프 개체를 null로 보이는 것입니다 분명히 널 포인터를 throw 할 때 업데이트를 호출하려고합니다. 나는 정말 명백한 것을 보지 못했을 수 있습니다. 그래프 코드는 아래와 같이 정말 간단하다 :
public class Graph extends View
Paint paint= new Paint();
public float x;
public float y;
Vector<CoOrdinate> coVec = new Vector<CoOrdinate>();
public Graph(Context context) {
super(context);
}
public void onDraw(Canvas canvas)
{
Log.v("Line 28 Graph.java","Y: "+y+"X: "+x);
canvas.drawCircle(x, y, 2, paint);
Log.v(this.toString(),"onDraw in the graph");
}
public void update()
{
Log.v("Line 31 of Graph.java","");
x+=100;
y+=100;
paint.setColor(Color.GREEN);
}
}
어떤 도움에 감사드립니다. 감사. 이후
02-11 19:03:00.933: DEBUG/AndroidRuntime(301): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
02-11 19:03:00.933: DEBUG/AndroidRuntime(301): CheckJNI is ON
02-11 19:03:02.012: DEBUG/AndroidRuntime(301): --- registering native functions ---
02-11 19:03:03.942: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=graphAndroid.graphs/.Oscilloscope }
02-11 19:03:04.062: DEBUG/AndroidRuntime(301): Shutting down VM
02-11 19:03:04.082: DEBUG/jdwp(301): adbd disconnected
02-11 19:03:04.122: INFO/AndroidRuntime(301): NOTE: attach of thread 'Binder Thread #3' failed
02-11 19:03:04.263: INFO/ActivityManager(60): Start proc graphAndroid.graphs for activity graphAndroid.graphs/.Oscilloscope: pid=308 uid=10040 gids={1015}
02-11 19:03:05.263: INFO/ARMAssembler(60): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x361990:0x361a9c] in 6676000 ns
02-11 19:03:05.493: INFO/System.out(308): Creating dummy source (dummy:1)
02-11 19:03:05.493: INFO/System.out(308): No Motes:1
02-11 19:03:05.503: VERBOSE/Line 129 Oscilloscope.java(308): Made it to here
02-11 19:03:05.503: VERBOSE/Line 135 Oscilloscope.java(308): Made it here
02-11 19:03:05.513: VERBOSE/Line 137 Oscilloscope.java(308): Made it here
02-11 19:03:05.513: VERBOSE/Line 114 MoteIF.java(308): Third constructor
02-11 19:03:05.513: VERBOSE/Line 121 MoteIF.java(308): Made it here
02-11 19:03:05.513: VERBOSE/Line 123 MoteIF.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 127 MoteIF.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 130 MoteIF.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 69 PhoenixSource.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 71 PhoenixSource.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 74 PhoenixSource.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 133 MoteIF.java(308): Made it here
02-11 19:03:05.523: VERBOSE/Line 138 MoteIF.java(308): Made it here
02-11 19:03:05.533: VERBOSE/Line 140 MoteIF.java(308): Made it here
02-11 19:03:05.543: VERBOSE/Line 142 MoteIF.java(308): Made it here
02-11 19:03:05.543: VERBOSE/Line 138 Oscilloscope.java(308): Made it here
02-11 19:03:05.543: VERBOSE/Line 140 Oscilloscope.java(308): Made it to here
02-11 19:03:05.783: VERBOSE/Line 28 Graph.java(308): Y: 0.0X: 0.0
02-11 19:03:05.793: VERBOSE/[email protected](308): onDraw in the graph
02-11 19:03:05.823: INFO/ActivityManager(60): Displayed activity graphAndroid.graphs/.Oscilloscope: 1679 ms (total 1679 ms)
02-11 19:03:07.543: INFO/System.out(308): SimulatedOscilloscopePacketSource moteId is 0
02-11 19:03:07.543: VERBOSE/1(308): A test, line 424 OscilloscopeMsg class
02-11 19:03:07.543: WARN/dalvikvm(308): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
02-11 19:03:07.563: ERROR/AndroidRuntime(308): FATAL EXCEPTION: Thread-8
02-11 19:03:07.563: ERROR/AndroidRuntime(308): java.lang.NullPointerException
02-11 19:03:07.563: ERROR/AndroidRuntime(308): at graphAndroid.graphs.Oscilloscope.messageReceived(Oscilloscope.java:108)
02-11 19:03:07.563: ERROR/AndroidRuntime(308): at net.tinyos.message.Receiver.packetReceived(Receiver.java:210)
02-11 19:03:07.563: ERROR/AndroidRuntime(308): at net.tinyos.packet.PhoenixSource.dispatch(PhoenixSource.java:165)
02-11 19:03:07.563: ERROR/AndroidRuntime(308): at net.tinyos.packet.PhoenixSource.packetDipatchLoop(PhoenixSource.java:157)
02-11 19:03:07.563: ERROR/AndroidRuntime(308): at net.tinyos.packet.PhoenixSource.run(PhoenixSource.java:174)
02-11 19:03:07.613: WARN/ActivityManager(60): Force finishing activity graphAndroid.graphs/.Oscilloscope
02-11 19:03:07.932: WARN/IInputConnectionWrapper(129): showStatusIcon on inactive InputConnection
02-11 19:03:08.463: INFO/ARMAssembler(60): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x36b288:0x36b344] in 746000 ns
John, 스택 추적을 추가하십시오. – DJC
Logcat 출력으로 편집 한 그 ive에 대해 죄송합니다. 감사. –
NPE는 Oscilloscope.java의 108 번 라인에 있습니다. 그 줄에 어떤 코드가 있습니까? –