1 글고, 6 확인란과 (다른 활동) 1 텍스트 뷰글고에서 텍스트를 확인하고 체크 박스 상태는 HTTP POST와 URL에이를 보내
확인하면 는 첫째 온 클릭 버튼, 글고에서 텍스트를 가져 변수에 저장하고 확인란가 쳤다되었는지 확인 여부, 재향 군인 생성 : 나는이 원하는 리바일 및 setText to TRUE else FALSE.
둘째 HTTP POST 방법을 통해 URL에 확인란 및 글고의 7 개 변수를 보낼 수 있습니다. 그 후 서버 응답을 받고 그것을 보여주십시오 다른 활동으로 TextView이것은 내 JAVA 파일이지만 작동하지 않습니다. 누구든지이 코드를 수정할 수 있습니까? 46 : 19130-19130 29.451/com.royalrandhawa.xemp E/AndroidRuntime : FATAL EXCEPTION : 메인 공정 :
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import static com.royalrandhawa.untitled.R.id.mainSearch;
/**
* Created by ROYAL on 10/11/2017.
*/
public class SurfAnony extends Activity {
String one, two, three, four, five, six;
CheckBox First, Second, Third, Fourth, Fifth, Sixth;
TextView content;
Button search = (Button) findViewById(R.id.surfNowBtn);
EditText query = (EditText) findViewById(mainSearch);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.surf_anony);
First = (CheckBox) findViewById(R.id.eurlchb);
Second = (CheckBox) findViewById(R.id.epagechb);
Third = (CheckBox) findViewById(R.id.alckchb);
Fourth = (CheckBox) findViewById(R.id.ftcchb);
Fifth = (CheckBox) findViewById(R.id.djschb);
Sixth = (CheckBox) findViewById(R.id.dsbchb);
//First CheckBox
First.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (First.isChecked()) {
one = "true";
} else {
one = "false";
}
}
});
//Second CheckBox
Second.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Second.isChecked()) {
two = "true";
} else {
two = "false";
}
}
});
//Third CheckBox
Third.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Third.isChecked()) {
three = "true";
} else {
three = "false";
}
}
});
//Fourth CheckBox
Fourth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Fourth.isChecked()) {
four = "true";
} else {
four = "false";
}
}
});
//Fifth CheckBox
Fifth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Fifth.isChecked()) {
five = "true";
} else {
five = "false";
}
}
});
//Sixth CheckBox
Sixth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Sixth.isChecked()) {
six = "true";
} else {
six = "false";
}
}
});
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
GetText();
} catch (Exception ex) {
content.setText(" url exeption! ");
}
}
});
}
public void GetText() throws UnsupportedEncodingException {
// Get user defined values
String q = query.getText().toString();
// Create data variable for sent values to server
String data = URLEncoder.encode("q", "UTF-8")
+ "=" + URLEncoder.encode(q, "UTF-8");
data += "&" + URLEncoder.encode("eurl", "UTF-8") + "="
+ URLEncoder.encode(one, "UTF-8");
data += "&" + URLEncoder.encode("epage", "UTF-8")
+ "=" + URLEncoder.encode(two, "UTF-8");
data += "&" + URLEncoder.encode("alck", "UTF-8")
+ "=" + URLEncoder.encode(three, "UTF-8");
data += "&" + URLEncoder.encode("ftc", "UTF-8")
+ "=" + URLEncoder.encode(four, "UTF-8");
data += "&" + URLEncoder.encode("djs", "UTF-8")
+ "=" + URLEncoder.encode(five, "UTF-8");
data += "&" + URLEncoder.encode("dsb", "UTF-8")
+ "=" + URLEncoder.encode(six, "UTF-8");
String text = "";
BufferedReader reader = null;
// Send data
try {
// Defined URL where to send data
URL url = new URL("my url here!");
// Send POST data request
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while ((line = reader.readLine()) != null) {
// Append server response in string
sb.append(line + "\n");
}
text = sb.toString();
} catch (Exception ex) {
} finally {
try {
reader.close();
} catch (Exception ex) {
}
}
// Show response on activity
content.setText(text);
}
}
이
는 로그 캣10-15 16 com.royalrandhawa.xemp , PID : 19130 java.lang.RuntimeException가 : java.lang.NullPointerException이 을 android.ap에서 : 활동 ComponentInfo {com.royalrandhawa.xemp/com.royalrandhawa.xemp.SurfAnony}을 (를) 인스턴스화 할 수 없습니다 안드로이드에서 android.app.ActivityThread.access $ 800 (ActivityThread.java:151)에서 p.ActivityThread.performLaunchActivity android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390)에서 (ActivityThread.java:2264) .app.ActivityThread $ H.handleMessage (ActivityThread.java:1321) android.os.Handler.dispatchMessage (Handler.java:110)의 at android.os.Looper.loop (Looper.java:193) at android .app.ActivityThread.main (ActivityThread.java:5299) at java.lang.reflect.Method.invokeNative (네이티브 메소드) at java.lang.reflect.Method.invo ke (Method.java:515) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:825) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:641)) dalvik.system.NativeStart.main (기본 방법) 에서 에 의해 발생 :. com.royalrandhawa.xemp.SurfAnony에서 android.app.Activity.findViewById (Activity.java:1899) 에서 java.lang.NullPointerException이 (SurfAnony.java30) at java.lang.Class.newInstanceImpl (네이티브 메소드) at java.lang.Class.newInstance (Class.java:1215) android.app.Instrumentation.newActivit y (계측.자바 : 1061) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2390) android.app.ActivityThread.access $ 800 에서 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2255) (ActivityThread에서 된 .java : android.os.Looper.loop에서 android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1321) android.os.Handler.dispatchMessage (Handler.java:110에서 ) 151) (Looper.java:193) android.app.ActivityThread.main (ActivityThread.java:5299) at java.lang.reflect com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:825) 에서 java.lang.reflect.Method.invoke에서 .Method.invokeNative (기본 방법) (Method.java:515) dalvik.system.NativeStart.main에서 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:641) (기본 방법)에서
Put Log(); 각 조건 (if, else)에서 작동하고 문제가있는 LogCat을 살펴보십시오. – Bobo159951
고용주 –