我的APK上的一些错误。 [英] Some Errors On my APK.

查看:83
本文介绍了我的APK上的一些错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我安装这个apk时,活动会显示,但它不执行任何后面的代码。

我认为我的AndroidMainfest.xml中出现了问题。但是在哪里?<这是我的AndroidMainfest.xml:

when i install this apk,the activity shows,but it doesn't execute any behind code.
I think there is something wrong in my AndroidMainfest.xml.But where?

this is my AndroidMainfest.xml:

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



    package="com.example.notepad"



    android:versionCode="1"



    android:versionName="1.0" >



    <uses-sdk



        android:minSdkVersion="8"



        android:targetSdkVersion="17" />

    <application



        android:allowBackup="true"



        android:icon="@drawable/ic_launcher"



        android:label="@string/app_name"



        android:theme="@style/AppTheme" >

        <activity



            android:name="com.example.notepad.MainActivity"



            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>



这是activmainity_.xml:


this is activmainity_.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context="com.example.notepad.MainActivity$PlaceholderFragment" >

    <EditText

        android:id="@+id/editText"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:inputType="text"

        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button

        android:id="@+id/Add"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignBaseline="@+id/editText"

        android:layout_alignBottom="@+id/editText"

        android:layout_alignParentRight="true"

        android:text="@string/addText" />

    <TextView

        android:id="@+id/textView"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/editText"

        android:layout_alignRight="@+id/Add"

        android:layout_below="@+id/editText"

        android:layout_marginTop="43dp"

        android:text="@string/showText" />

</RelativeLayout>



这是MainActivity.java(后面的行为)


this is MainActivity.java(behind behand)

package com.example.notepad;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

@SuppressLint("ShowToast")
public class MainActivity extends ActionBarActivity {

	@SuppressLint("ShowToast")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Toast.makeText(this,".在创建时",1000);
		//为啥不行呢??????把这个注释了,拷代码
//		saveFile();
		
		Button iButton=(Button)findViewById(R.id.Add);
		iButton.setOnClickListener(new View.OnClickListener() {
			@SuppressLint("ShowToast")
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), ".在点击时",1000);
				try {
					toSaveAndShow();
					Toast.makeText(getApplicationContext(),".在Try完成后",1000);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

		Toast.makeText(this, ".在新方法调用时",1000);
		File myFile=new File("data.txt");
		if(myFile.exists()!=true){
			try {
				myFile.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		try {
			//创建date对象记录时间
			Date myDate=new Date();
			//读取字符串。创建文件流。写入文件,关闭
			OutputStream out = new FileOutputStream(myFile,true);
			EditText youSay=(EditText)findViewById(R.id.editText);
			byte[] bufferByte=new byte[youSay.getText().length()+1];
			bufferByte=youSay.getText().toString().getBytes();
			out.write(bufferByte);
			String inStr="\t"+myDate.getDate();
			byte[] systemInfo=inStr.getBytes();
			out.write(systemInfo);
			out.close();
			//在textview中显示文本,病清空原来的文本
			TextView myView=(TextView)findViewById(R.id.textView);
			myView.setText(youSay.getText().toString()+inStr);
			youSay.setText("");
		Toast.makeText(this, ".我完成了",1000);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		Toast.makeText(this, ".出错了!",1000);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	protected void saveFile(){
		Button iButton=(Button)findViewById(R.id.Add);
		iButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), ".在点击时",1000);
				try {
					toSaveAndShow();
					Toast.makeText(getApplicationContext(),".在Try完成后",1000);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

	}
	private void toSaveAndShow() throws IOException {
		// TODO Auto-generated method stub
				
		
		Toast.makeText(this, ".在新方法调用时",1000);
		File myFile=new File("data.txt");
		if(myFile.exists()!=true){
			myFile.createNewFile();
		}
		try {
			//创建date对象记录时间
			Date myDate=new Date();
			//读取字符串。创建文件流。写入文件,关闭
			OutputStream out = new FileOutputStream(myFile,true);
			EditText youSay=(EditText)findViewById(R.id.editText);
			byte[] bufferByte=new byte[youSay.getText().length()+1];
			bufferByte=youSay.getText().toString().getBytes();
			out.write(bufferByte);
			String inStr="\t"+myDate.getDate();
			byte[] systemInfo=inStr.getBytes();
			out.write(systemInfo);
			out.close();
			//在textview中显示文本,病清空原来的文本
			TextView myView=(TextView)findViewById(R.id.textView);
			myView.setText(youSay.getText().toString()+inStr);
			youSay.setText("");
		Toast.makeText(this, ".我完成了",1000);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		Toast.makeText(this, ".出错了!",1000);
		}
	}

	@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;
		}
	}

}

推荐答案

PlaceholderFragment\" >

<EditText

android:id=\"@+id/editText\"

android:layout_width=\"wrap_content\"

android:layout_height=\"wrap_content\"

< span class=\"code-attribute\"> android:layout_alignParentLeft=\"true\"

android:layout_alignParentTop=\"true\"

android:inputType=\"text\"

android:ems=\"10\" >

<requestFocus />
</EditText>

<Button

android:id=\"@+id/Add\"
$b$ b android:layout_width=\"wrap_content\"

android:layout_height=\"wrap_content\"

android:layout_alignBaseline=\"@+id/editText\"

android:layout_alignBottom=\"@+i d/editText\"

android:layout_alignParentRight=\"true\"

android:text=\"@string/addText\" />

<TextView

android:id=\"@+id/textView\"

android:layout_width=\"wrap_content\"

android:layout_height=\"wrap_content\"

android:layout_alignLeft=\"@+id/editText\"

android:layout_alignRight=\"@+id/Add\"

android:layout_below=\"@+id/editText\"

android:layout_marginTop=\"43dp\"

android:text=\"@string/showText\" />

</RelativeLayout>
PlaceholderFragment" > <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:inputType="text" android:ems="10" > <requestFocus /> </EditText> <Button android:id="@+id/Add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText" android:layout_alignBottom="@+id/editText" android:layout_alignParentRight="true" android:text="@string/addText" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText" android:layout_alignRight="@+id/Add" android:layout_below="@+id/editText" android:layout_marginTop="43dp" android:text="@string/showText" /> </RelativeLayout>



this is MainActivity.java(behind behand)


this is MainActivity.java(behind behand)

package com.example.notepad;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

@SuppressLint("ShowToast")
public class MainActivity extends ActionBarActivity {

	@SuppressLint("ShowToast")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Toast.makeText(this,".在创建时",1000);
		//为啥不行呢??????把这个注释了,拷代码
//		saveFile();
		
		Button iButton=(Button)findViewById(R.id.Add);
		iButton.setOnClickListener(new View.OnClickListener() {
			@SuppressLint("ShowToast")
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), ".在点击时",1000);
				try {
					toSaveAndShow();
					Toast.makeText(getApplicationContext(),".在Try完成后",1000);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

		Toast.makeText(this, ".在新方法调用时",1000);
		File myFile=new File("data.txt");
		if(myFile.exists()!=true){
			try {
				myFile.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		try {
			//创建date对象记录时间
			Date myDate=new Date();
			//读取字符串。创建文件流。写入文件,关闭
			OutputStream out = new FileOutputStream(myFile,true);
			EditText youSay=(EditText)findViewById(R.id.editText);
			byte[] bufferByte=new byte[youSay.getText().length()+1];
			bufferByte=youSay.getText().toString().getBytes();
			out.write(bufferByte);
			String inStr="\t"+myDate.getDate();
			byte[] systemInfo=inStr.getBytes();
			out.write(systemInfo);
			out.close();
			//在textview中显示文本,病清空原来的文本
			TextView myView=(TextView)findViewById(R.id.textView);
			myView.setText(youSay.getText().toString()+inStr);
			youSay.setText("");
		Toast.makeText(this, ".我完成了",1000);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		Toast.makeText(this, ".出错了!",1000);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	protected void saveFile(){
		Button iButton=(Button)findViewById(R.id.Add);
		iButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), ".在点击时",1000);
				try {
					toSaveAndShow();
					Toast.makeText(getApplicationContext(),".在Try完成后",1000);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

	}
	private void toSaveAndShow() throws IOException {
		// TODO Auto-generated method stub
				
		
		Toast.makeText(this, ".在新方法调用时",1000);
		File myFile=new File("data.txt");
		if(myFile.exists()!=true){
			myFile.createNewFile();
		}
		try {
			//创建date对象记录时间
			Date myDate=new Date();
			//读取字符串。创建文件流。写入文件,关闭
			OutputStream out = new FileOutputStream(myFile,true);
			EditText youSay=(EditText)findViewById(R.id.editText);
			byte[] bufferByte=new byte[youSay.getText().length()+1];
			bufferByte=youSay.getText().toString().getBytes();
			out.write(bufferByte);
			String inStr="\t"+myDate.getDate();
			byte[] systemInfo=inStr.getBytes();
			out.write(systemInfo);
			out.close();
			//在textview中显示文本,病清空原来的文本
			TextView myView=(TextView)findViewById(R.id.textView);
			myView.setText(youSay.getText().toString()+inStr);
			youSay.setText("");
		Toast.makeText(this, ".我完成了",1000);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		Toast.makeText(this, ".出错了!",1000);
		}
	}

	@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;
		}
	}

}


这篇关于我的APK上的一些错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆