我在运行android应用程序时遇到这个错误
05-25 23:58:44.251:E/AndroidRuntime(1128):java.lang.RuntimeException:无法启动activity ComponentInfo{info.AndroidHive.TabsSwipe/Info.AndroidHive.TabsSwipe.MainActivity}:Android.View.InflateException:二进制XML文件行#46:inflating类时出错
这里是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();
}
}
}
}
}
android:textColor="@string/text_color"
textcolor
应该是(A)RGB整数,如#12345678
或对color
资源的引用,如@color/text_color
。它不能是对string
资源的引用。
我怎样才能解决这类问题?问题在于setOnClickListener,它给了我一个NullPointerException。如果你还需要什么,请告诉我。 这是日志中的错误:
问题内容: 在添加异步任务之前,我已经对代码进行了一些更改,我的应用程序可以正常运行其远程服务器上的身份验证用户名和密码,但是在登录成功消息消失后无法启动其他活动。有人建议我现在添加一个异步任务,但是我输入正确的用户名和密码后它将停止工作。当我输入错误的用户名和密码时,其工作正常将显示错误的用户名密码消息。如果有人能够知道会出现什么错误,请帮助我。 码- 日志猫 QuestionnActivi
以下是我的日志转发
我有一个浮动按钮在一个片段,并希望传递意图到另一个活动。但是,当我按下浮动按钮时,导致“无法启动activity ComponentInfo”错误。 ------------编辑---------------------- 下面是我的意图代码:
我已经搜索了这个错误,并找到了许多解决方案,但我无法解决这个问题,因为我是Android的初学者 舱单在下面 安装应用程序后,它第一次工作,但当我们关闭并重新打开时,它崩溃了,不幸的是,应用程序已经关闭,你有任何想法,它将非常感谢:) 谢了!