简体   繁体   English

使用android SDK的Eclipse中的Android Application NFC错误

[英]Android Application NFC errors in eclipse with android SDK

I am working on an android application in eclipse with the android SDK and I keep getting these errors that I cannot understand(This is my first application for android) and these errors may stem from either my lack of coding skills or the setup in the XML file, so I hate to flood you, the reader, with all of this but here goes, Output: 我正在使用eclipse使用android SDK开发一个android应用程序,并且不断收到这些我无法理解的错误(这是我的第一个android应用程序),这些错误可能是由于我缺乏编码技能或XML设置引起的文件,所以我不愿意将所有这些东西淹没您,读者,但是输出:

    12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.os.Looper.loop(Looper.java:137)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.ActivityThread.main(ActivityThread.java:4745)
12-27 13:01:07.872: E/AndroidRuntime(621):  at java.lang.reflect.Method.invokeNative(Native Method)
12-27 13:01:07.872: E/AndroidRuntime(621):  at java.lang.reflect.Method.invoke(Method.java:511)
12-27 13:01:07.872: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-27 13:01:07.872: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-27 13:01:07.872: E/AndroidRuntime(621):  at dalvik.system.NativeStart.main(Native Method)
12-27 13:01:07.872: E/AndroidRuntime(621): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
12-27 13:01:07.872: E/AndroidRuntime(621):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-27 13:01:07.872: E/AndroidRuntime(621):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.Activity.setContentView(Activity.java:1867)
12-27 13:01:07.872: E/AndroidRuntime(621):  at com.chuggle.clink.MainActivity.onCreate(MainActivity.java:31)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.Activity.performCreate(Activity.java:5008)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-27 13:01:07.872: E/AndroidRuntime(621):  ... 11 more
12-27 13:01:07.872: E/AndroidRuntime(621): Caused by: java.lang.reflect.InvocationTargetException
12-27 13:01:07.872: E/AndroidRuntime(621):  at java.lang.reflect.Constructor.constructNative(Native Method)
12-27 13:01:07.872: E/AndroidRuntime(621):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
12-27 13:01:07.872: E/AndroidRuntime(621):  ... 24 more
12-27 13:01:07.872: E/AndroidRuntime(621): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060000 a=-1 r=0x7f060000}
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.content.res.Resources.loadDrawable(Resources.java:1892)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.View.<init>(View.java:3336)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.view.ViewGroup.<init>(ViewGroup.java:427)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.widget.LinearLayout.<init>(LinearLayout.java:176)
12-27 13:01:07.872: E/AndroidRuntime(621):  at android.widget.LinearLayout.<init>(LinearLayout.java:172)
12-27 13:01:07.872: E/AndroidRuntime(621):  ... 27 more
12-27 13:01:12.192: I/Process(621): Sending signal. PID: 621 SIG: 9


XML: XML:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="16" ></uses-sdk>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:permission="android.permission.NFC" android:enabled="true" android:debuggable="true">
        <activity
            android:name="com.chuggle.clink.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>

Java: Java:

package com.chuggle.clink;
import java.util.Calendar;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.nfc.tech.NfcF;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class MainActivity extends Activity {
    NfcAdapter nfcAdapter;
    private PendingIntent pint;
    private IntentFilter[] mesfilt;
    private String[][] TList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText messageholder = (EditText) findViewById(R.id.ToSend);
        final Button TButton = (ToggleButton) findViewById(R.id.SendButton);
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter == null) return;
        pint = PendingIntent.getActivity(this, 0,
        new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
        IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
        try {
            ndef.addDataType("*/*");
        } catch (MalformedMimeTypeException e) {
            throw new RuntimeException("fail", e);
        }
        mesfilt = new IntentFilter[] {
                ndef,
        };
        TList = new String[][] { new String[] { NfcF.class.getName() } };
        if (nfcAdapter == null) return;
        TButton.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                sendMessage(messageholder.getText().toString());
            }
        });
    }
    String resolveIntent(Intent intent) {
        NdefMessage[] msgs = null;
        if(intent.equals(NfcAdapter.ACTION_NDEF_DISCOVERED)){
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            if(rawMsgs!=null){
                msgs = new NdefMessage[rawMsgs.length];
                for(int i=0;i<rawMsgs.length;i++){
                    msgs[i] = (NdefMessage) rawMsgs[i];
                }
            }
        } 
        else {
        return("Recieving Error");
        }
        return msgs.toString();
    }
    public void sendMessage(String OrToSend){
        Calendar rightNow = Calendar.getInstance();
        OrToSend = OrToSend+" --"+rightNow.getTime().toString();
        byte[] textBytes = OrToSend.getBytes();
        NdefMessage MessageToSend = null;
        try {
            MessageToSend = new NdefMessage(textBytes);
        } catch (FormatException e) {
            e.printStackTrace();
            MessageUpdate("Message Error, Cannot Send");
        }
        nfcAdapter.setNdefPushMessage(MessageToSend, this);

    }
    @Override
    public void onResume() {
        super.onResume();
        nfcAdapter.enableForegroundDispatch(this, pint, mesfilt, TList);
    }

    @Override
    public void onNewIntent(Intent intent) {
        Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);
        Log.i(intent.toString(), resolveIntent(intent));
    }
    @Override
    public void onPause() {
        super.onPause();
        nfcAdapter.disableForegroundDispatch(this);
    }
    public void MessageUpdate(String NewString){
        TextView M1 = (TextView)findViewById(R.id.M1);
        TextView M2 = (TextView)findViewById(R.id.M2);
        TextView M3 = (TextView)findViewById(R.id.M3);
        TextView M4 = (TextView)findViewById(R.id.M4);
        TextView M5 = (TextView)findViewById(R.id.M5);
        TextView M6 = (TextView)findViewById(R.id.M6);
        TextView M7 = (TextView)findViewById(R.id.M7);
        TextView M8 = (TextView)findViewById(R.id.M8);
        TextView M9 = (TextView)findViewById(R.id.M9);
        TextView M10 = (TextView)findViewById(R.id.M10);
        TextView M11 = (TextView)findViewById(R.id.M11);
        TextView M12 = (TextView)findViewById(R.id.M12);
        TextView M13 = (TextView)findViewById(R.id.M13);
        TextView M14 = (TextView)findViewById(R.id.M14);
        TextView M15 = (TextView)findViewById(R.id.M15);
        TextView M16 = (TextView)findViewById(R.id.M16);
        TextView M17 = (TextView)findViewById(R.id.M17);
        TextView M18 = (TextView)findViewById(R.id.M18);
        TextView M19 = (TextView)findViewById(R.id.M19);
        TextView M20 = (TextView)findViewById(R.id.M20);
        TextView M21 = (TextView)findViewById(R.id.M21);
        M21.setText(M20.getText());
        M20.setText(M19.getText());
        M19.setText(M18.getText());
        M18.setText(M17.getText());
        M17.setText(M16.getText());
        M16.setText(M15.getText());
        M15.setText(M14.getText());
        M14.setText(M13.getText());
        M13.setText(M12.getText());
        M12.setText(M11.getText());
        M11.setText(M10.getText());
        M10.setText(M9.getText());
        M9.setText(M8.getText());
        M8.setText(M7.getText());
        M7.setText(M6.getText());
        M6.setText(M5.getText());
        M4.setText(M3.getText());
        M2.setText(M1.getText());
        M1.setText(NewString);
    }
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}


Sorry it is all quite ugly, I am pretty sure my code is quite wrong in most of it, but that isn't the piece I care about, feel free to help on that but really what I need to know is why these errors are happening and how to fix them. 抱歉,这很丑陋,我可以肯定我的代码大部分都错了,但这不是我关心的部分,可以随时提供帮助,但实际上我需要知道的是为什么这些错误是发生以及如何修复它们。 Sorry this is a massive post. 抱歉,这是一个庞大的职位。 Thanks. 谢谢。

The line in your trace 轨迹中的线

android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060000 a=-1 r=0x7f060000}

suggests that you are trying to point to an undefined resource (Color/Path) in one of your layout files. 建议您尝试指向布局文件之一中的未定义资源(颜色/路径)。

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

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