获取错误"无法启动myWeb *(我的应用程序名称)*" 有谁能够帮我 ? 我是新手,刚开始编写android。
我在eclipse上运行了这个,当从ADT启动应用程序时,它给出了错误!!
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myweb"
android:versionCode="1"
android:versionName="1.0"
android:name="testing.android.application.three.MainActivityThreeActivity"
>
<uses-permission android:name="android.permission.INTERNET"
/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myweb.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@style/AppTheme"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:id="@+id/mainLayout"
>
<EditText
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="105dp"
android:ems="10"
android:textColor="#00FF00"
android:typeface="monospace"
android:hint="Email Address or Phone Number" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/password"
android:layout_centerVertical="true"
android:ems="10"
android:textColor="#00FF00"
android:typeface="monospace"
android:hint="Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/login1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/password"
android:layout_below="@+id/password"
android:layout_marginTop="18dp"
android:minWidth="180dip"
android:text="Log In" />
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/login1"
android:layout_toRightOf="@+id/login1"
android:visibility="invisible" />
</RelativeLayout>
MainActivity.java
package com.example.myweb;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton button = (ImageButton) findViewById(R.id.login1);
EditText emailBox = (EditText)findViewById(R.id.email);
EditText passwordBox = (EditText)findViewById(R.id.password);
final String emailId = emailBox.getText().toString();
final String passwordId = passwordBox.getText().toString();
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
getUserLoggedIn(emailId,passwordId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void getUserLoggedIn(String email,String password) throws ClientProtocolException, IOException{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("localhost/testand.php");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("email", email));
pairs.add(new BasicNameValuePair("password", password));
post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(post);
}
}
答案 0 :(得分:0)
使用如下的AsyncTask并在onCreate
private class DownloadFilesTask extends AsyncTask<emailId, passwordId> {
protected Long doInBackground(URL... urls) {
getUserLoggedIn(emailId,passwordId);
return totalSize;
}
protected void onPostExecute(Long result) {
Log.v("Webpage","Done");
}
}
并致电onCreate
try {
new DownloadFilesTask().execute(emailId,passwordId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 1 :(得分:0)
实际上这已经解决了...... 。
在activity_main.xml
中我使用了<button>
标记,但在.java
我使用ImageButton
来通过ID调用它。
虽然愚蠢我通过在java文件中使用Button
类而不是ImageButton
来解决它
已更改
ImageButton button = (ImageButton) findViewById(R.id.login1);
以强>
Button button = (Button) findViewById(R.id.login1);
此修复仅针对我的代码。因此,如果有人像这样绕过错误,那就是重新检查代码而不是闲聊问题。