运行android应用程序时出现此错误
05-25 23:58:44.251:E / AndroidRuntime(1128):java.lang.RuntimeException:无法启动活动ComponentInfo {info.androidhive.tabsswipe / info.androidhive.tabsswipe.MainActivity}:android .view.InflateException:二进制XML文件行#46:错误导致类
这是XML代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00aff0" >
<!-- Header Starts-->
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<!-- Logo Start-->
<ImageView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"/>
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="@layout/footer_repeat"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
</LinearLayout>
<!-- Footer Ends -->
<!-- Login Form -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_below="@id/header">
<!-- Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@string/text_color"
android:text="Email"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="20dip"
android:id="@+id/edit_username"
android:singleLine="true"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@string/text_color"
android:text="Password"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:id="@+id/edit_password"
android:password="true"/>
<!-- Login button -->
<Button
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:textColor="@string/text_color"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Login"/>
<!-- Link to Registration Screen -->
<!-- <TextView android:id="@+id/link_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_marginBottom="40dip"
android:text="New to EdgeAccounts? Register here"
android:gravity="center"
android:textSize="20dip"
android:textColor="#0b84aa"/>-->
</LinearLayout>
<!-- Login Form Ends -->
</RelativeLayout>
</ScrollView>
这是java代码
package info.androidhive.tabsswipe;
import java.io.BufferedReader;
import java.io.Console;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button GetServerData = (Button) findViewById(R.id.btn_login);
/*Click Listener for Login Button*/
GetServerData.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// WebServer Request URL
String serverURL = "http://ott.edgeaccounts.com/Webservices/LoginService.php";
// Use AsyncTask execute Method To Prevent ANR Problem
new LongOperation().execute(serverURL);
}
});
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
/*@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//View rootView = inflater.inflate(R.layout.fragment_main, container,
//false);
//return rootView;
}*/
}
private class LongOperation extends AsyncTask<String, Void, Void> {
// Required initialization
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);
String data ="";
EditText user = (EditText) findViewById(R.id.edit_username);
EditText pass = (EditText) findViewById(R.id.edit_password);
//TextView output = (TextView) findViewById(R.id.output);
/*PreExecute Method*/
protected void onPreExecute() {
// NOTE: You can call UI Element here.
//Start Progress Dialog (Message)
Dialog.setMessage("Please wait..");
Dialog.show();
try{
// Set Request parameter
data +="&" + URLEncoder.encode("email", "UTF-8") + "="+user.getText() + "&" +URLEncoder.encode("password", "UTF-8") + "="+pass.getText() ;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected Void doInBackground(String... urls) {
/************ Make Post Call To Web Server ***********/
BufferedReader reader=null;
// Send data
try
{
// Defined URL where to send data
URL url = new URL(urls[0]);
// Send POST data request
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( data );
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null)
{
// Append server response in string
sb.append(line + " ");
}
// Append Server Response To Content String
Content = sb.toString();
}
catch(Exception ex)
{
Error = ex.getMessage();
}
finally
{
try
{
reader.close();
}
catch(Exception ex) {}
}
/*****************************************************/
return null;
}
/*Called at the end*/
protected void onPostExecute(Void unused) {
Dialog.dismiss();
if (Error != null)
{
//output.setText(Error);
} else
{
// Show Response Json On Screen (activity)
/****************** Start Parse Response JSON Data *************/
String OutputData = "";
JSONObject jsonResponse;
try {
/****** Creates a new JSONObject with name/value mappings from the JSON string. ********/
jsonResponse = new JSONObject(Content);
/***** Returns the value mapped by name if it exists and is a JSONArray. ***/
/******* Returns null otherwise. *******/
JSONArray jsonMainNode = jsonResponse.optJSONArray("Android");
/*********** Process each JSON Node ************/
int lengthJsonArr = jsonMainNode.length();
for(int i=0; i < lengthJsonArr; i++)
{
/****** Get Object for each JSON node.***********/
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
/******* Fetch node values **********/
String email = jsonChildNode.optString("email").toString();
String adminId = jsonChildNode.optString("adminId").toString();
OutputData+="email "+ email +"\nAdminId "+adminId;
}
/****************** End Parse Response JSON Data *************/
//Show Parsed Output on screen (activity)
// output.setText(OutputData);
Intent myIntent = new Intent(MainActivity.this, DetailsPage.class);
myIntent.putExtra("data",OutputData);
startActivity(myIntent);
////////////////////////////////////////
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}
答案 0 :(得分:3)
android:textColor="@string/text_color"
textColor
应该是{A} RGB整数,如#12345678
,或者是对color
资源的引用,例如@color/text_color
。它不能是对string
资源的引用。