1

Androidボタンを使用してat_commandの値を変更しようとしています

logcatを呼び出す"intOfFloat(float f)"と、btnLeftListener

01-23 16:17:28.610: E/AndroidRuntime(1154): java.lang.NullPointerException

私がこれを解決するのを手伝ってください:)

String at_cmd = "";
FloatBuffer fb;
IntBuffer ib;
int  PORT=5556;
float speed = (float)0.1;
int seq = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    
    btnLeft=(Button)findViewById(R.id.LeftBtn);
    btnLeft.setOnClickListener(btnLeftListener);
}
public Button.OnClickListener btnLeftListener=
      new Button.OnClickListener(){
      @Override
        public void onClick(View arg0) {
            at_cmd = "AT*PCMD=" + (seq++) + ",1," + intOfFloat(-speed)+",0,0,0";
    }

};
public int intOfFloat(float f) {
    fb.put(0, f);
    return ib.get(0);
}

logcat

01-23 16:17:28.591: W/dalvikvm(1154): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-23 16:17:28.610: E/AndroidRuntime(1154): FATAL EXCEPTION: main
01-23 16:17:28.610: E/AndroidRuntime(1154): java.lang.NullPointerException
01-23 16:17:28.610: E/AndroidRuntime(1154):     at com.example.dronedivideandroid.DroneMain.intOfFloat(DroneMain.java:60)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at com.example.dronedivideandroid.DroneMain$1.onClick(DroneMain.java:70)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at android.view.View.performClick(View.java:4084)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at android.view.View$PerformClick.run(View.java:16966)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at android.os.Handler.handleCallback(Handler.java:615)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at android.os.Looper.loop(Looper.java:137)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at java.lang.reflect.Method.invoke(Method.java:511)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-23 16:17:28.610: E/AndroidRuntime(1154):     at dalvik.system.NativeStart.main(Native Method)
01-23 16:17:28.631: W/ActivityManager(163):   Force finishing activity com.example.dronedivideandroid/.DroneMain
01-23 16:17:28.641: W/WindowManager(163): Failure taking screenshot for (246x410) to layer 21010
01-23 16:17:29.150: W/ActivityManager(163): Activity pause timeout for ActivityRecord{4154a830 com.example.dronedivideandroid/.DroneMain}
01-23 16:17:29.351: I/Choreographer(262): Skipped 37 frames!  The application may be doing too much work on its main thread.
01-23 16:17:30.591: I/Process(1154): Sending signal. PID: 1154 SIG: 9
01-23 16:17:30.601: I/ActivityManager(163): Process com.example.dronedivideandroid (pid 1154) has died.
01-23 16:17:30.601: I/WindowState(163): WIN DEATH: Window{414043e0 com.example.dronedivideandroid/com.example.dronedivideandroid.DroneMain paused=false}
01-23 16:17:30.691: W/InputMethodManagerService(163): Got RemoteException sending setActive(false) notification to pid 1154 uid 10047
01-23 16:17:40.091: W/ActivityManager(163): Activity destroy timeout for ActivityRecord{4154a830 com.example.dronedivideandroid/.DroneMain}
01-23 16:19:52.800: D/dalvikvm(248): GC_CONCURRENT freed 383K, 7% free 8537K/9095K, paused 6ms+5ms, total 46ms
01-23 16:23:49.971: E/ThrottleService(163): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
01-23 16:27:27.310: D/dalvikvm(248): GC_CONCURRENT freed 384K, 7% free 8537K/9095K, paused 17ms+6ms, total 56ms
4

3 に答える 3

1

変数の1つが初期化されていないため、次の変数に値があることを確認する必要があります。

seq、、、、。speed_ fb_ib

于 2013-01-23T08:30:47.743 に答える
0

変数を使用する前に、変数fbibが初期化されている(nullではない)ことを確認してください

public int intOfFloat(float f) {
if(fb != null) fb.put(0, f);
if(ib != null) return ib.get(0);
else return 0;
}
于 2013-01-23T08:30:55.320 に答える
0

デバイスでこれをテストしたので、これが正しい答えかもしれません... !!!!!

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

 import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
String at_cmd = "";
FloatBuffer fb;
IntBuffer ib;
int  PORT=5556;
float speed = (float)0.1;
int seq = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main);
   Button  btnLeft=(Button)findViewById(R.id.button1);
    btnLeft.setOnClickListener(btnLeftListener);
}
public OnClickListener btnLeftListener=
      new OnClickListener(){


    @Override
    public void onClick(View arg0) {
         at_cmd = "AT*PCMD=" + String.valueOf(seq++) + ",1," + intOfFloat(-speed)+",0,0,0";

         System.out.println("Ans----->"+at_cmd);
    }

};
public int intOfFloat(float f) {
    if(fb != null) fb.put(0, f);
    if(ib != null) return ib.get(0);
    else return 0;

}

}

そして、私は次の出力を得ました... !!!

AT * PCMD=1,1,0,0,0,0。

それ以外の場合はチェックしてください...!!!!!!!

于 2013-01-23T10:00:33.753 に答える