以下是我的android代码列表,包括java,xml
Java代码:
package thesis.file;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ListActivity;
import android.net.ParseException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.ListView;
import android.widget.Toast;
public class Eventlogs extends ListActivity {
JSONArray jArray;
String result = null;
InputStream is = null;
StringBuilder sb=null;
int ct_id;
String ct_name;
ListView yourListView = getListView();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventlogs);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://amlan.aytee.info/event.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//paring data
try{
jArray = new JSONArray(result);
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
ct_id=json_data.getInt("e_id");
ct_name=json_data.getString("event");
//ct_datetime=json_data.get
}
}catch(JSONException e1){
Toast.makeText(getBaseContext(), "No events found" ,Toast.LENGTH_LONG).show();
} catch (ParseException e1) {
e1.printStackTrace();
}
}
}
Android清单代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.file"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".ThesisActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name =".MenuClass" android:label ="@string/app_name"></activity>
<activity android:name =".SalesReport" android:label ="@string/app_name"></activity>
<activity android:name =".EventLogs" android:label ="@string/app_name"></activity>
<activity android:name =".LanStatus" android:label ="@string/app_name"></activity>
</application>
eventlogs.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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Logs"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
我的代码有什么问题?这是日志cat错误:
12-21 01:30:19.014: W/dalvikvm(708): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
12-21 01:30:19.023: E/AndroidRuntime(708): Uncaught handler: thread main exiting due to uncaught exception
12-21 01:30:19.058: E/AndroidRuntime(708): android.content.ActivityNotFoundException: Unable to find explicit activity class {thesis.file/thesis.file.Eventlogs}; have you declared this activity in your AndroidManifest.xml?
我对列表活动和活动感到困惑
这是代码:
package thesis.file;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.widget.EditText;
import android.widget.TextView;
public class ThesisActivity extends Activity {
/** Called when the activity is first created. */
Button btnLogin;
EditText txtUsername, txtPassword;
TextView txtError;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnLogin = (Button) findViewById(R.id.btnLogin);
txtUsername = (EditText) findViewById(R.id.txtUsername);
txtPassword = (EditText) findViewById(R.id.txtPassword);
txtError = (TextView) findViewById(R.id.txtError);
/*btnLogin.setOnClickListener((android.view.View.OnClickListener) this);*/
//Login = (Button)findViewById(R.id.btnLogin);
/*@Override
public void onDestroy()
{
n
super.onDestroy();
}*/
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", txtUsername.getText().toString()));
postParameters.add(new BasicNameValuePair("password", txtPassword.getText().toString()));
//String valid = "1";
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://amlan.aytee.info/user.php", postParameters); //Enter Your remote PHP,ASP, Servlet file link
String res=response.toString();
// res = res.trim();
res= res.replaceAll("\\s+","");
//error.setText(res);
if(res.contains("1")){
txtError.setText("correct username");
//txtError.setText(res);
Intent i = new Intent(ThesisActivity.this, MenuClass.class);
startActivity(i);
}
else {
txtError.setText("incorrect username");
}
} catch (Exception e) {
txtUsername.setText(e.toString());
}
}
});
}
}
答案 0 :(得分:0)
你的包裹错了。
清单中的:
package="my.file"
在课程中:
package thesis.file;