当按下菜单按钮时,Android,Google Spread Sheet崩溃

时间:2015-03-11 23:50:16

标签: java android logcat

嘿伙计我的当前应用程序存在问题,问题是由于某种原因,每当我尝试单击菜单中的“保存注册”按钮时,应用程序崩溃。这是说println消息,但我确定我已经在一个字符串中放置了hello world?

我想提一下,我一直在关注Youtube发布的教程,将数据发布到谷歌电子表格和其他教程来创建这个AP管理器,您可能已经注意到我的代码,但下一步是将数组列表保存到电子表格是下一步。但是现在我不能简单地通过菜单按钮将“Hello World”消息保存到Spreadsheets中

我的日志猫显示:

Process: com.example.gavin.wifiattendance, PID: 2266
java.lang.NullPointerException: println needs a message
        at android.util.Log.println_native(Native Method)
        at android.util.Log.i(Log.java:160)
        at com.example.gavin.wifiattendance.MainActivity.postData(MainActivity.java:93)
        at com.example.gavin.wifiattendance.MainActivity.onMenuItemSelected(MainActivity.java:143)
        at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1127)
        at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
        at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
        at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
        at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:165)
        at android.widget.AdapterView.performItemClick(AdapterView.java:300)
        at android.widget.AbsListView.performItemClick(AbsListView.java:1143)

我的主要活动文件:

public class MainActivity extends Activity{

boolean wasApEnabled = false;
static AccessPoint wifiAP;
private WifiManager wifi;
static Button apButton;
static TextView textView;
final String myTag = "DocsUpload";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    apButton = (Button) findViewById(R.id.toggleBtn);
    textView = (TextView) findViewById(R.id.wifiClients);

    apButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            wifiAP.toggleWifiAP(wifi, MainActivity.this);
        }
    });

    wifiAP = new AccessPoint(this);
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    scan();

    //getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|WindowManager.LayoutParams.FLAG_DIM_BEHIND);

}

private void scan(){
    wifiAP.getClientList(false, new FinishScanListener() {

        @Override
        public void onFinishScan(final ArrayList<ClientScanResult> clients) {
            textView.setText("WifiApState:" + wifiAP.getWifiApState()+ "\n\n");
            textView.append("Clients: \n");
            for (ClientScanResult clientScanResult : clients){
                textView.append("====================\n");
                textView.append("ipAddress: " + clientScanResult.getIpAddress() + "\n");
                textView.append("Device: " + clientScanResult.getDevice() + "\n");
                textView.append("macAddress: " + clientScanResult.getMacAddress() + "\n");
                textView.append("isReachable: " + clientScanResult.isReachable() + "\n");

            }
        }
    });
}

public void postData() {

    String fullUrl = "https://docs.google.com/forms/d/1yipuuXd5V53Ol12U24Cl2H4RIdYtm622jIk13Zo26cM/formResponse";
    HttpRequest mReq = new HttpRequest();
    String col1 = "Hello";
    String col2 = "World";

    String data = "entry_272641491=" + URLEncoder.encode(col1) + "&" +
            "entry_130393492=" + URLEncoder.encode(col2);
    String response = mReq.sendPost(fullUrl, data);
    Log.i(myTag, response);
}

@Override
public void onResume() {
    super.onResume();
    if (wasApEnabled) {
        if (wifiAP.getWifiApState() != wifiAP.WIFI_STATE_ENABLED && wifiAP.getWifiApState() != wifiAP.WIFI_STATE_ENABLING) {
            wifiAP.toggleWifiAP(wifi, MainActivity.this);
        }
    }
    updateStatusDisplay();
}

@Override
public void onPause() {
    super.onPause();
    boolean wifiApIsOn = wifiAP.getWifiApState()==wifiAP.WIFI_STATE_ENABLED || wifiAP.getWifiApState()==wifiAP.WIFI_STATE_ENABLING;
    if (wifiApIsOn){
        wasApEnabled = true;
        wifiAP.toggleWifiAP(wifi, MainActivity.this);
    }else {
        wasApEnabled = false;
    }
    updateStatusDisplay();
}

public static void updateStatusDisplay(){
    if (wifiAP.getWifiApState()==wifiAP.WIFI_STATE_ENABLED || wifiAP.getWifiApState()==wifiAP.WIFI_STATE_ENABLING){
        apButton.setText("Turn Off");
    }else {
        apButton.setText("Turn on");
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0,0,0, "Get Clients");
    menu.add(0,1,0, "Save Register");
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return super.onCreateOptionsMenu(menu);
}

public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()){
        case 0:
            scan();
            break;
        case 1:
            postData();
            break;
    }
    return super.onMenuItemSelected(featureId, item);
}

}

编辑:删除日志后,即使按下按钮,电子表格也不再获取任何信息。

    03-12 11:41:56.444    1903-1921/com.example.gavin.wifiattendance W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5c08180, error=EGL_SUCCESS
03-12 11:41:58.696    1903-1903/com.example.gavin.wifiattendance D/WifiAttendance﹕ Setting httpPost headers
03-12 11:41:58.696    1903-1903/com.example.gavin.wifiattendance D/Your App Name Here﹕ https://docs.google.com/forms/d/1yipuuXd5V53Ol12U24Cl2H4RIdYtm622jIk13Zo26cM/formResponse?entry_272641491=Hello&entry_130393492=World
03-12 11:41:58.697    1903-1903/com.example.gavin.wifiattendance E/WifiAttendance﹕ HttpUtils: android.os.NetworkOnMainThreadException
03-12 11:41:58.697    1903-1903/com.example.gavin.wifiattendance D/WifiAttendance﹕ Returning value:null

1 个答案:

答案 0 :(得分:0)

您在postData中将空字符串传递给Log.i.不要这样做。几乎可以肯定,因为HTTP请求是异步的,你还没有响应。由于它只是一个日志,我删除该行。