繁体   English   中英

无法解决类型错误

[英]Cannot be resolved to a type error

我得到一个“注册无法解析为我的代码中的类型错误,我不知道为什么。我强烈感觉这是一个Eclipse错误,除非有人可以看到其他内容。我只是在编辑时随机遇到此错误另一页,所以我不知道为什么要得到这个。

我尝试清理项目,甚至重建项目,仍然遇到此错误。

这是Eclipse中错误的屏幕截图:

日食

更奇怪的是,我在键入代码时尝试查看可用的类,而Registration.java没有显示在可用列表中:

在此处输入图片说明

关于如何使其显示在列表中的任何想法?

这是我的代码:

package com.smeet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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 com.sencide.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;



public class AndroidLogin extends Activity implements OnClickListener {


    Button ok,back,exit;
    TextView result;




    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       setContentView(R.layout.main);



        // Login button clicked
        ok = (Button)findViewById(R.id.btn_login);
        ok.setOnClickListener(this);


        result = (TextView)findViewById(R.id.tbl_result);



    }









    public void postLoginData() {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();


        // login.php returns true if username and password match in db 
        HttpPost httppost = new HttpPost("http://www.somewebsite.com/android/login.php");

        try {




            // Add user name and password
            EditText uname = (EditText)findViewById(R.id.txt_username);
            String username = uname.getText().toString();



            EditText pword = (EditText)findViewById(R.id.txt_password);
            String password = pword.getText().toString();

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", username));
            nameValuePairs.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            Log.w("SENCIDE", "Execute HTTP Post Request");
            HttpResponse response = httpclient.execute(httppost);

            String str = inputStreamToString(response.getEntity().getContent()).toString();
            Log.w("SENCIDE", str);

            if(str.toString().equalsIgnoreCase("true"))
            {
                Log.w("SENCIDE", "TRUE");
                result.setText("Login Successful! Please Wait...");   
            }else
            {
                Log.w("SENCIDE", "FALSE");
                result.setText(str);                
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    private StringBuilder inputStreamToString(InputStream is) {
        String line = "";
        StringBuilder total = new StringBuilder();
        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        // Read response until the end
        try {
            while ((line = rd.readLine()) != null) { 
                total.append(line); 
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Return full string
        return total;
    }


    //clicking register button will start up Register xml
    public void RegisterButton(View view) {

          Intent intent = new Intent(this, Registration.class);
          startActivity(intent);

    }




    @Override
    public void onClick(View view) {
                postLoginData();




                // turns the text in the textview "Tbl_result" into a text string called "tblresult"
                TextView tblresult = (TextView) findViewById(R.id.tbl_result);




        // If "tblresult" text string matches the string "Login Successful! Please Wait..." exactly, it will switch to next activity
                if (tblresult.getText().toString().equals("Login Successful! Please Wait...")) {
                      Intent intent = new Intent(this, Homepage.class);
                      EditText uname2 = (EditText)findViewById(R.id.txt_username);
                      String username2 = uname2.getText().toString();
                      intent.putExtra("username2", username2);
                      startActivity(intent);
                   }    






    }

}

我的清单:

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

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

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name="com.sencide.AndroidLogin"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.sencide.NextActivity"
            android:label="@string/title_activity_next" >
        </activity>
           <activity
            android:name="com.sencide.Registration"
            android:label="@string/title_activity_registration" >
        </activity>
        <activity
            android:name="com.sencide.Homepage"
            android:label="@string/title_activity_next_screen" >
        </activity>


    </application>

</manifest>

这是我的Registration.java

package com.smeet;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.sencide.R;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;


class RequestTask extends AsyncTask<String, String, String>{
      String responseString = null;


    @Override
    protected String doInBackground(String... uri) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;

        try {
            response = httpclient.execute(new HttpGet(uri[0]));
            StatusLine statusLine = response.getStatusLine();
            if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                String responseString = null;
                responseString = out.toString();
                Log.d("check response", responseString);


            } else{
                //Closes the connection.
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }
        } catch (ClientProtocolException e) {
            //TODO Handle problems..
        } catch (IOException e) {
            //TODO Handle problems..
        }
        return responseString;
    }


    protected void onPostExecute(String result) {
        super.onPostExecute(result);


    }







String result = null;

public class Registration extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
          TextView detail = (TextView)findViewById(R.id.resulttext);
            detail.setText(result);
    }


    public void SubmitRegistration(View view) {




           // assign text in fields to string values
           EditText first = (EditText)findViewById(R.id.first);
           String first2 = first.getText().toString();

           EditText last = (EditText)findViewById(R.id.last);
           String last2 = last.getText().toString();

           EditText display = (EditText)findViewById(R.id.display);
           String display2 = display.getText().toString();
           //calculates the number of characters in the display field
           int length2 = display2.length();


           EditText email = (EditText)findViewById(R.id.email);
           String email2 = email.getText().toString();


           EditText password = (EditText)findViewById(R.id.password);
           String password2 = password.getText().toString();


           EditText vpassword = (EditText)findViewById(R.id.vpassword);
           String vpassword2 = vpassword.getText().toString();
           //calculates the number of characters in the password field
           int length = vpassword2.length();






    // verifying the following in order:  Passwords match? A Password field is empty?  
                                        //Password and Display Name less than 6 characters long? Email contains an @ sign and a period?   
           if(!vpassword2.equals(password2))
           {
               Toast.makeText(getApplicationContext(), "Passwords do not match!", Toast.LENGTH_SHORT).show(); 


           }
           else if (password2.isEmpty() || vpassword2.isEmpty()){

               Toast.makeText(getApplicationContext(), "Password field is empty", Toast.LENGTH_SHORT).show(); 
           }
           else if (length < 6 || length2 < 6 ) {

               Toast.makeText(getApplicationContext(), "Password and Display Name must be at least 6 characters long", Toast.LENGTH_LONG).show(); 

           }

           else if (!email2.contains("@") || !email2.contains(".")){

               Toast.makeText(getApplicationContext(), "Must enter valid email address.", Toast.LENGTH_SHORT).show(); 

           }

           else {


               //send php with all the data to server for validation and insertion into table
               new RequestTask().execute("http://www.somewebsite.com/android/registercheck.php?first=" + first2 + "&last=" + last2 + "&dispname=" + display2 + "&email=" + email2 + "&password=" + password2 );                       



           }
   }







}

}

根据您帖子中的评论和图像,我怀疑您在Registration.java中

public class Register ...

什么时候应该

public class Registration ...

另外,既然您已经添加了代码,那么Registration类应该是独立的,而不是嵌套在RequestTask中。

Registration类位于GCM backend module 如果使用Android Studio,则集成是无缝的,但是在Eclipse中,您必须手动做一些技巧才能使其正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM