我正在制作app并将数据放入mysql。 当我的同学在她的笔记本电脑上运行项目时,没关系。 但它不适用于我的笔记本电脑。 我正在尝试解决问题,但应用程序仍然停止。 我不知道为什么..
这是代码和日志
public class DateAndTime extends Activity {
EditText Name, Mobile, Addrs, Fee;
TextView Otime, Ctime;
String pic,name, mobile, addrs, otime, ctime, fee;// 바꾸고 이미지도 추가.
ImageView Pic;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
private TextView mText1;
private TextView mText2;
private Button mPickDate1;
private Button mPickTime1;
private Button mPickDate2;
private Button mPickTime2;
private int mYear1;
private int mYear2;
private int mMonth1;
private int mMonth2;
private int mDay1;
private int mDay2;
private int mHour1;
private int mHour2;
private int mMinute1;
private int mMinute2;
//Dialog
static final int DATE_DIALOG_ID_1 = 0;
static final int TIME_DIALOG_ID_1 = 1;
static final int DATE_DIALOG_ID_2 = 2;
static final int TIME_DIALOG_ID_2 = 3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.avtivity_date_time);
mText1 = (TextView) findViewById(R.id.text1);
mPickDate1 = (Button) findViewById(R.id.pickDate1);
mPickTime1 = (Button) findViewById(R.id.pickTime1);
mText2 = (TextView) findViewById(R.id.text2);
mPickDate2 = (Button) findViewById(R.id.pickDate2);
mPickTime2 = (Button) findViewById(R.id.pickTime2);
mPickDate1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID_1);
}
});
mPickDate2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID_2);
}
});
mPickTime1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID_1);
}
});
mPickTime2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(TIME_DIALOG_ID_2);
}
});
final Calendar c = Calendar.getInstance();
mYear1 = c.get(Calendar.YEAR);
mMonth1 = c.get(Calendar.MONTH);
mDay1 = c.get(Calendar.DAY_OF_MONTH);
mHour1 = c.get(Calendar.HOUR_OF_DAY);
mMinute1 = c.get(Calendar.MINUTE);
mYear2 = c.get(Calendar.YEAR);
mMonth2 = c.get(Calendar.MONTH);
mDay2 = c.get(Calendar.DAY_OF_MONTH);
mHour2 = c.get(Calendar.HOUR_OF_DAY);
mMinute2 = c.get(Calendar.MINUTE);
updateDisplay();
Pic = (ImageView)findViewById(R.id.pic);
Name = (EditText) findViewById(R.id.et_owner);
Mobile = (EditText) findViewById(R.id.et_mob);
Addrs = (EditText) findViewById(R.id.et_addrs);
Otime = (TextView) findViewById(R.id.text1);
Ctime = (TextView) findViewById(R.id.text2);
Fee = (EditText) findViewById(R.id.et_fee);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
public void updateDisplay() {
mText1.setText(String.format("시작 : %d년 %d월 %d일 %d시 %d분", mYear1, mMonth1 + 1, mDay1, mHour1, mMinute1));
mText2.setText(String.format("종료 : %d년 %d월 %d일 %d시 %d분", mYear2, mMonth2 + 1, mDay2, mHour2, mMinute2));
}
public DatePickerDialog.OnDateSetListener mDateSetListener1 =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mYear1 = year;
mMonth1 = monthOfYear;
mDay1 = dayOfMonth;
updateDisplay();
}
};
public DatePickerDialog.OnDateSetListener mDateSetListener2 =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mYear2 = year;
mMonth2 = monthOfYear;
mDay2 = dayOfMonth;
updateDisplay();
}
};
public TimePickerDialog.OnTimeSetListener mTimeSetListener1 =
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour1 = hourOfDay;
mMinute1 = minute;
updateDisplay();
}
};
public TimePickerDialog.OnTimeSetListener mTimeSetListener2 =
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour2 = hourOfDay;
mMinute2 = minute;
updateDisplay();
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID_1:
return new DatePickerDialog(this, mDateSetListener1, mYear1, mMonth1, mDay1);
case TIME_DIALOG_ID_1:
return new TimePickerDialog(this, mTimeSetListener1, mHour1, mMinute1, false);
case DATE_DIALOG_ID_2:
return new DatePickerDialog(this, mDateSetListener2, mYear2, mMonth2, mDay2);
case TIME_DIALOG_ID_2:
return new TimePickerDialog(this, mTimeSetListener2, mHour2, mMinute2, false);
}
return null;
}
public void saveInfo(View view) {
pic = "default";
name = Name.getText().toString();
mobile = Mobile.getText().toString();
addrs = Addrs.getText().toString();
otime = Otime.getText().toString();
ctime = Ctime.getText().toString();
fee = Fee.getText().toString();
DateAndTime.BackgroundTask backgroundTask = new DateAndTime.BackgroundTask();
backgroundTask.execute(pic, name, mobile, addrs, otime, ctime, fee);
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("ParkAddInfo Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://35.160.135.119/add_park_info.php"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
class BackgroundTask extends AsyncTask<String, Void, String> {
String park_add_info_url;
@Override
protected void onPreExecute() {
park_add_info_url = "http://35.160.135.119/add_park_info.php"; // insert the Domain name http://androidtut.comli.com//add_info.php
}
@Override
protected String doInBackground(String... args) {
HashMap<String, String> param = new HashMap<String, String>();
param.put("pic",args[0]);
param.put("owner",args[1]);
param.put("mobile",args[2]);
param.put("addrs",args[3]);
param.put("otime",args[4]);
param.put("ctime",args[5]);
param.put("fee",args[6]);
try {
URL url = new URL(park_add_info_url);
HttpURLConnection httpURLConnection =(HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
StringBuilder sb = new StringBuilder();
for(Map.Entry item : param.entrySet())
{
sb.append(item.getKey().toString());
sb.append("=");
String value = item.getValue().toString();
if(value.isEmpty())
{
sb.append("");
}else
{
sb.append(URLEncoder.encode(value,"UTF-8"));
}
sb.append("&");
}
stringBuilder.append(URLEncoder.encode(pic,"UTF-8"));
stringBuilder.append(URLEncoder.encode(name,"UTF-8"));
stringBuilder.append(URLEncoder.encode(mobile,"UTF-8"));
stringBuilder.append(URLEncoder.encode(addrs,"UTF-8"));
stringBuilder.append(URLEncoder.encode(otime,"UTF-8"));
stringBuilder.append(URLEncoder.encode(ctime,"UTF-8"));
stringBuilder.append(URLEncoder.encode(fee,"UTF-8"));
String data_string = sb.toString(); =URLEncoder.encode(stringBuilder.toString(),"utf-8");
bufferedWriter.write(data_string);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
inputStream.close();
httpURLConnection.disconnect();
return "One row of data inserted..";
} catch (IOException e) {//TODO:check network dialog window
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
}
}
这是日志
11/15 23:00:15: Launching app
No apk changes detected since last installation, skipping installation of C:\Android\1113GMDemo1\app\build\outputs\apk\app-debug.apk
$ adb shell am force-stop com.example.jina.a1105gmdemo
$ adb shell am start -n "com.example.jina.a1105gmdemo/com.example.jina.a1105gmdemo.DateAndTime" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Connecting to com.example.jina.a1105gmdemo
I/System.out: Sending WAIT chunk
W/ActivityThread: Application com.example.jina.a1105gmdemo is waiting for the debugger on port 8100...
I/dalvikvm: Debugger is active
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:8629', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1304)
I/MultiDex: VM with version 1.6.0 does not have multidex support
I/MultiDex: install
I/MultiDex: MultiDexExtractor.load(/data/app/com.example.jina.a1105gmdemo-9.apk, false)
I/MultiDex: Detected that extraction must be performed.
I/MultiDex: Trying to delete old file /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-8.apk.classes2.dex of size 2898496
I/MultiDex: Deleted old file /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-8.apk.classes2.dex
I/MultiDex: Trying to delete old file /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-8.apk.classes2.zip of size 934986
I/MultiDex: Deleted old file /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-8.apk.classes2.zip
I/MultiDex: Extraction is needed for file /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-9.apk.classes2.zip
I/MultiDex: Extracting /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-9.apk.classes-1719707400.zip
I/MultiDex: Renaming to /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-9.apk.classes2.zip
I/MultiDex: Extraction success - length /data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-9.apk.classes2.zip: 934986
I/MultiDex: load found 1 secondary dex files
D/dalvikvm: DexOpt: --- BEGIN 'com.example.jina.a1105gmdemo-9.apk.classes2.zip' (bootstrap=0) ---
D/dalvikvm: DexOpt: --- END 'com.example.jina.a1105gmdemo-9.apk.classes2.zip' (success) ---
D/dalvikvm: DEX prep '/data/data/com.example.jina.a1105gmdemo/code_cache/secondary-dexes/com.example.jina.a1105gmdemo-9.apk.classes2.zip': unzip in 69ms, rewrite 772ms
I/MultiDex: install done
I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
I/PersonaManager: getPersonaService() name persona_policy
I/PersonaManager: getPersonaService() name persona_policy
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x416d3da0)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jina.a1105gmdemo, PID: 16909
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jina.a1105gmdemo/com.example.jina.a1105gmdemo.DateAndTime}: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5479)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.support.v4.widget.NestedScrollView.addView(NestedScrollView.java:387)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:770)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:366)
at android.app.Activity.setContentView(Activity.java:2031)
at com.example.jina.a1105gmdemo.DateAndTime.onCreate(DateAndTime.java:86)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5479)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
您可以通过转到MainActivity来解决问题,向下滚动到显示setContentView(R.layout。 your_layout_name )的部分;并在按住Ctrl(Windows)或Cmd(Mac)的同时单击 your_layout_name 。这将带您进入布局文件。在这里,您应该在开头看到一个ScrollView开始标记,在结尾看到一个结束标记。只需将其更改为更像这样的内容:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="This is your first item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="This is your second item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="This is your third item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>