java - android项目有红色x但代码没有错误

标签 java android eclipse

我正在尝试运行 android 项目。该项目在项目文件夹上有一个红色的 x,但没有一个子文件夹有那个红色的 x。没有突出显示显示错误的代码。不幸的是,我的项目都没有执行。当我作为项目运行时,它会提示此错误。

enter image description here

它也不会在问题选项卡中显示任何错误。

我该如何解决这个问题?

我的java构建路径

enter image description here

编辑

这是我的代码

public class AndroidLoginActivity extends Activity implements OnClickListener {
EditText username, password;
Button login;

String user, pass;
HttpClient httpclient;
HttpPost httppost;
ArrayList<NameValuePair> nameValuePair;
HttpResponse response;
HttpEntity entity;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initialise();
}

private void initialise() {
    // TODO Auto-generated method stub
    username = (EditText)findViewById(R.id.etUsername);
    password = (EditText)findViewById(R.id.etPassword);
    login = (Button)findViewById(R.id.btnLogin);

    login.setOnClickListener(this);
}

public void onClick(View v) {
    httpclient = new DefaultHttpClient();
    httppost = new HttpPost("http://10.0.2.2/android_login/index.php");

    user = username.getText().toString();
    pass = password.getText().toString();

    try {
        nameValuePair = new ArrayList<NameValuePair>();

        nameValuePair.add(new BasicNameValuePair("username", user));
        nameValuePair.add(new BasicNameValuePair("password", pass));
        httppost.setEntity(new  UrlEncodedFormEntity(nameValuePair));
        response = httpclient.execute(httppost);
        if(response.getStatusLine().getStatusCode() == 200) {
            entity = response.getEntity();

            if(entity != null) {
                InputStream instream = entity.getContent();
                JSONObject jsonResponse = new JSONObject(convertStreamToString(instream));
                String retUser = jsonResponse.getString("username"); //mysql table field
                String retPass = jsonResponse.getString("password");

                if(username.equals(retUser) && password.equals(retPass)) {
                    SharedPreferences sp = getSharedPreferences("logindetails",0); 
                    SharedPreferences.Editor spedit = sp.edit();
                    spedit.putString("user", user);
                    spedit.putString("pass", pass);
                    spedit.commit();
                    Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getBaseContext(), "Login Failed", Toast.LENGTH_SHORT).show();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "Login Failed", Toast.LENGTH_SHORT).show();
    }
}

public static String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}
}

这是我的 main.xml

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/etUsername"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Username..." >

</EditText>

<EditText
    android:id="@+id/etPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:text="Password..." />

<Button
    android:id="@+id/btnLogin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Login" />

</LinearLayout>

这是我的 list 文件

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zafar.androidlogin"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".AndroidLoginActivity"
        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>

错误日志

enter image description here

最佳答案

我正在回答我自己的问题,这样如果其他人有同样的问题,他们将很容易找到解决方案。

解决方案

我删除了存在于此路径 C:\Users\Administrator\.android 上的文件 debug.keystore

然后我清理了项目并且它工作了。

关于java - android项目有红色x但代码没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10763439/

相关文章:

android - Android 编程断言

php - 好的http3 : writing to MySQL from Android

android - Android App 的 WebView 中的 Vimeo Player 问题

java - 如何减少Java构造函数的重复性和臃肿性?

java - 需要帮助 - Java Else/If 语句

java - 无法使用selenium webdriver点击 "Browse"按钮

java - 惯性滚动算法?

java - Eclipse 中的奇怪标志

java - 贾斯珀异常(exception)。找不到 Struts 调度程序

java - 为什么我无法导入 android.os.StrictMode?