MySQLに接続するためにAndroid studioからApacheに接続しようとしています。
一応、プログラムをまとめてみたのですが、エラーが起きてしまい、はじかれてしまいます....
因みにエラー
↓↓
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.n0190.test, PID: 4066
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.n0190.test/com.example.n0190.test.MainActivity}: java.lang.ClassCastException: com.example.n0190.test.MainActivity cannot be cast to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassCastException: com.example.n0190.test.MainActivity cannot be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
↑↑ここまで
package com.example.n0190.test;
import android.os.AsyncTask;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
} @Override protected String doInBackground(Void... params) { HttpURLConnection con = null; URL url = null; String urlSt = "http://172.18.99.125:90/php.php"; try { // URLの作成 url = new URL(urlSt); // 接続用HttpURLConnectionオブジェクト作成 con = (HttpURLConnection)url.openConnection(); // リクエストメソッドの設定 con.setRequestMethod("POST"); // リダイレクトを自動で許可しない設定 con.setInstanceFollowRedirects(false); // URL接続からデータを読み取る場合はtrue con.setDoInput(true); // URL接続にデータを書き込む場合はtrue con.setDoOutput(true); // 接続 con.connect(); // ① } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); }
}
何が間違ってるのか教えていただけると嬉しいです!
よろしくお願いします!!
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。