如何使用类和子类修复setContentView和super.onCreate方法?

时间:2019-01-12 22:16:51

标签: java android

所以我试图将不同的按钮输出加载到子类中,所以我需要setContentView和onCreate方法(我认为),以便可以触发findViewById函数来触发使用按钮的不同方法。

我在这里输入了错误的代码

esp_err_t index_post_handler(httpd_req_t *req)
{
    uint8_t buffer[100];
    wifi_config_t wifi_config;
    httpd_req_recv(req, (char *) buffer, 100);

    if (httpd_query_key_value((char *) buffer, "ssid", (char *) wifi_config.sta.ssid, 32) == ESP_ERR_NOT_FOUND) {
        httpd_resp_set_status(req, "400");
        httpd_resp_send(req, "SSID required", -1);
        return ESP_OK;
    }
    if (httpd_query_key_value((char *) buffer, "password", (char *) wifi_config.sta.password, 64) == ESP_ERR_NOT_FOUND) {
        httpd_resp_set_status(req, "400");
        httpd_resp_send(req, "Password is required", -1);
        return ESP_OK;
    }

    if (strlen((char *) wifi_config.sta.ssid) < 1) {
        httpd_resp_set_status(req, "400");
        httpd_resp_send(req, "Invalid ssid", -1);
        return ESP_OK;
    }

    ESP_LOGI(TAG, "SSID: %s, Pass: %s", wifi_config.sta.ssid, wifi_config.sta.password);
    httpd_resp_send(req, "<h1>OK</h1>", -1);

    ESP_ERROR_CHECK(esp_wifi_stop());
    ESP_ERROR_CHECK(esp_wifi_restore());
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
    ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
    ESP_ERROR_CHECK(esp_wifi_start());

    return ESP_OK;
}


<html>
  <head>
    <title>Esp32</title>
    <meta charset='UTF-8'>
  </head>
  <body>
   <h1>Choose access point</h1>
   <form method="POST" action="/">{{p}}
     <br/><input type="text" name="password" placeholder="Wifi password"/>
     <br/><input type="submit" value="Save"/>
   </form>
  </body>
</html>

它显示了onCreate和setContentView上的问题,并且似乎对整个项目产生了错误。有没有人遇到过导致这个人显示不正确的问题?这仅适用于标记为LoadGuitar的子类。在我的主要班级...

public class LoadGuitar { 

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

工作正常!

请帮助任何人解决这个问题。谢谢。

1 个答案:

答案 0 :(得分:0)

oncreate()和setcontentview()是在Activity类中定义的;要覆盖或调用它们,必须使用LoadGuitar扩展Activity类;

public class LoadGuitar extends Activity{ 

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