应用程序适用于某些设备,但在其他设备上崩溃

时间:2014-11-06 11:18:59

标签: android sqlite

我刚将我的应用程序上传到Google Play商店并告诉我的朋友测试它。不幸的是,它给出了一个错误。

logcat的:

java.lang.RuntimeException: Unable to start activity ComponentInfo{karlis.mendzins.laimigasstundas2/karlis.mendzins.laimigasstundas2.Container}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
    at android.app.ActivityThread.access$700(ActivityThread.java:134)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4867)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
    at android.app.Activity.setContentView(Activity.java:1901)
    at karlis.mendzins.laimigasstundas2.Container.onCreate(Container.java:17)
    at android.app.Activity.performCreate(Activity.java:5047)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
    ... 11 more
Caused by: java.lang.IllegalStateException: Invalid tables
    at android.database.sqlite.SQLiteDatabase.findEditTable(SQLiteDatabase.java:971)
    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
    at karlis.mendzins.laimigasstundas2.SQLite.getAllRecords(SQLite.java:199)
    at karlis.mendzins.laimigasstundas2.MainFragment.otherList(MainFragment.java:1496)
    at karlis.mendzins.laimigasstundas2.MainFragment.onCreateView(MainFragment.java:83)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1099)
    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1201)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:292)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
    ... 21 more

这是我的清单:

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Container"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".HttpClient"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".Images"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".SQLite"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".InsertData"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".MainFragment"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".SocialMedia"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name=".AdFragment"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
        </activity>
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

这是Container.java文件:

package karlis.mendzins.laimigasstundas2;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.view.WindowManager;

public class Container extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_container);
    }
}

我的MainFragment.java:

package karlis.mendzins.laimigasstundas2;

import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class MainFragment extends Fragment {

    private TextView tvClock, tvHH, tvBT, tvBar, tvOffer, tvLikes, tvTimeS,
            tvTimeE, tvMinus, tvLoc;
    private Timer myTimer;
    Typeface font, fontN;
    ListView lv2;
    String imagePath;
    ImageButton locat;

    // SQLite Node names
    public static final String TAG_ARRAY = "0";
    public static final String TAG_COUNTRY = "country";
    public static final String TAG_DAY = "day";
    public static final String TAG_CITY = "city";
    public static final String TAG_BAR = "bar";
    public static final String TAG_TIMESTART = "timeStart";
    public static final String TAG_TIMEEND = "timeEnd";
    public static final String TAG_PLACELALO = "placeLaLo";
    public static final String TAG_DESCRIPTION = "description";
    public static final String TAG_LIKES = "likes";
    public static final String TAG_OFFER = "offer";
    public static final String TAG_LOGO = "logo";

    // Hashmap for ListView
    ArrayList<HashMap<String, String>> barList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.main_fragment, container, false);
        tvClock = (TextView) view.findViewById(R.id.tvClock);
        tvHH = (TextView) view.findViewById(R.id.tvHH);
        tvBT = (TextView) view.findViewById(R.id.tvBy);

        lv2 = (ListView) view.findViewById(R.id.list);
        barList = new ArrayList<HashMap<String, String>>();

        font = Typeface.createFromAsset(getActivity().getAssets(),
                "fonts/agencyfbbold.ttf");
        fontN = Typeface.createFromAsset(getActivity().getAssets(),
                "fonts/agencyfb.ttf");

        tvHH.setTypeface(font);
        tvBT.setTypeface(fontN);
        tvClock.setTypeface(font);

        myTimer = new Timer();
        myTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                TimerMethod();
            }
        }, 0, 5000);
        insertBars();
        otherList();
        return view;
    }

    private void insertBars() {
        SQLite db = new SQLite(getActivity());
        db.open();
        db.eraseDB();
        /*
         * day, country, city, bar, timeStart, timeEnd, location, description,
         * likes, offer
         */
        // Aussie Pub
        db.insertBar("monday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("tuesday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("wednesday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("thursday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("friday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("saturday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("sunday", "Latvia", "Riga", "aussie pub", "17:00",
                "18:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("monday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("tuesday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("wednesday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("thursday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("friday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("saturday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");
        db.insertBar("sunday", "Latvia", "Riga", "aussie pub", "18:00",
                "19:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Discount on all beers");

        db.insertBar("monday", "Latvia", "Riga", "aussie pub", "19:00",
                "20:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Buy one cocktail and get a second one for free");
        db.insertBar("tuesday", "Latvia", "Riga", "aussie pub", "19:00",
                "20:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Buy one cocktail and get a second one for free");
        db.insertBar("wednesday", "Latvia", "Riga", "aussie pub", "19:00",
                "20:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Buy one cocktail and get a second one for free");
        db.insertBar("thursday", "Latvia", "Riga", "aussie pub", "19:00",
                "20:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Buy one cocktail and get a second one for free");
        db.insertBar("friday", "Latvia", "Riga", "aussie pub", "19:00",
                "20:00", "Valnu Iela 43, Riga, Latvia", "It's a great bar",
                "465", "Buy one cocktail and get a second one for free");

        db.close();
        Log.w("taf", "done inserting bars");
        db.close();
    }

    private void TimerMethod() {
        getActivity().runOnUiThread(Timer_Tick);
    }

    private Runnable Timer_Tick = new Runnable() {
        public void run() {
            Calendar c = Calendar.getInstance();
            String minutes = "";
            String h = "";
            int min = c.get(Calendar.MINUTE);
            int hour = c.get(Calendar.HOUR);
            if (c.get(Calendar.AM_PM) == 1) {
                hour += 12;
            }
            if (min < 10) {
                minutes = "0" + min;
            } else {
                minutes = "" + min;
            }
            if (hour < 10) {
                h = "0" + hour;
            } else {
                h = "" + hour;
            }
            tvClock.setText("");
            tvClock.append(h + ":" + minutes);
        }
    };

    public void otherList() {
        SQLite db = new SQLite(getActivity());
        db.open();
        Calendar sCalendar = Calendar.getInstance();
        String day = sCalendar.getDisplayName(Calendar.DAY_OF_WEEK,
                Calendar.LONG, Locale.getDefault());
        Cursor c = db.getAllRecords(day);
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int position = 0;
        boolean time = false;

        if (c.moveToFirst()) {
            do {
                String country = c.getString(0);
                String city = c.getString(1);
                String bar = c.getString(2);
                String timeStart = c.getString(3);
                String[] separated = timeStart.split(":");
                int ho = Integer.parseInt(separated[0]);
                if (ho >= 24) {
                    ho = ho - 24;
                    timeStart = ho + ":" + separated[1];
                }
                String timeEnd = c.getString(4);
                separated = timeEnd.split(":");
                ho = Integer.parseInt(separated[0]);
                if (ho >= 24) {
                    ho = ho - 24;
                    timeEnd = ho + ":" + separated[1];
                }
                String placeLaLo = c.getString(5);
                String description = c.getString(6);
                String likes = c.getString(7);
                String offer = c.getString(8);

                String[] h = timeStart.split(":");
                int times = Integer.parseInt(h[0]);

                if (time == false) {
                    position++;
                    if (hour < (times + 1)) {
                        time = true;
                        position -= 2;
                    }
                }

                HashMap<String, String> bars = new HashMap<String, String>();
                bars.put(TAG_COUNTRY, country);
                bars.put(TAG_CITY, city);
                bars.put(TAG_BAR, bar);
                bars.put(TAG_TIMESTART, timeStart);
                bars.put(TAG_TIMEEND, timeEnd);
                bars.put(TAG_PLACELALO, placeLaLo);
                bars.put(TAG_DESCRIPTION, description);
                bars.put(TAG_LIKES, likes);
                bars.put(TAG_OFFER, offer);
                bar = Normalizer.normalize(bar, Normalizer.Form.NFD)
                        .replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
                bar = bar.replace(" ", "_");
                bar = bar.replace("'", "_");
                bar = bar.replace(".", "_");
                bar = bar.replace("-", "_");
                imagePath = getResources().getIdentifier(bar, "drawable",
                        "karlis.mendzins.laimigasstundas2")
                        + "";
                bars.put(TAG_LOGO, imagePath);
                barList.add(bars);

            } while (c.moveToNext());

            lv2.setAdapter(null);
            ListAdapter adapter2 = new SimpleAdapter(getActivity(), barList,
                    R.layout.json_single_item, new String[] { TAG_BAR,
                            TAG_TIMESTART, TAG_TIMEEND, TAG_OFFER, TAG_LOGO,
                            TAG_LIKES, TAG_PLACELALO }, new int[] { R.id.tvBar,
                            R.id.tvTimeS, R.id.tvTimeE, R.id.tvOffer,
                            R.id.ivLogo, R.id.tvLike, R.id.tvLoc }) {
                @Override
                public View getView(int position, View convertView,
                        ViewGroup parent) {
                    View v = convertView;
                    LayoutInflater li = (LayoutInflater) getActivity()
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = li.inflate(R.layout.json_single_item, null);
                    tvBar = (TextView) v.findViewById(R.id.tvBar);
                    tvOffer = (TextView) v.findViewById(R.id.tvOffer);
                    tvLikes = (TextView) v.findViewById(R.id.tvLike);
                    tvTimeS = (TextView) v.findViewById(R.id.tvTimeS);
                    tvTimeE = (TextView) v.findViewById(R.id.tvTimeE);
                    tvMinus = (TextView) v.findViewById(R.id.tvMinus);
                    tvLoc = (TextView) v.findViewById(R.id.tvLoc);
                    locat = (ImageButton) v.findViewById(R.id.ibLoc);

                    tvBar.setTypeface(font);
                    tvOffer.setTypeface(fontN);
                    tvLikes.setTypeface(fontN);
                    tvTimeS.setTypeface(font);
                    tvTimeE.setTypeface(fontN);
                    tvMinus.setTypeface(fontN);

                    return super.getView(position, v, parent);
                }
            };

            lv2.setAdapter(adapter2);
            lv2.setSelection(position);
        } else {
            Toast.makeText(getActivity(), "No database found",
                    Toast.LENGTH_LONG).show();
        }
        db.close();
    }
}

当我使用Eclipse上传应用程序时,它在我的设备(Ainol Novo Tab 7)和其他人(Samsung Galaxy S5)上工作正常。使用Galaxy Tab 4时,我发送了apk文件。 Galaxy S3和S3 mini出现问题。我自己似乎无法找到问题。

1 个答案:

答案 0 :(得分:1)

问题在于使用的语言。日历使用Locale.default()而不是英语,这在以后的代码中是预期的。

正确的代码是:

Calendar sCalendar = Calendar.getInstance();
String day = sCalendar.getDisplayName(Calendar.DAY_OF_WEEK,
            Calendar.LONG, Locale.ENGLISH);
Cursor c = db.getAllRecords(day);