小编Rog*_*ger的帖子

如何在android中访问资产?

编辑:修复它

ZipInputStream zin = new ZipInputStream(getAssets().open("totalkeys.zip")); 
Run Code Online (Sandbox Code Playgroud)

我从一个例子中得到了一个解压缩器( decompress ),它把一个字符串作为一个压缩文件的路径。但是由于我的资产中有该文件,所以我需要从那里读取它......好吧,到目前为止。

不幸的是它抛出我“错误/解压缩(24122):java.lang.ClassCastException:android.content.res.AssetManager$AssetInputStream”任何想法如何解决它?)

public class dec extends Activity {
/** Called when the activity is first created. */
@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        Toast.makeText(this, "hello, starting to unZipp!", 15500).show();

        String location = Environment.getExternalStorageDirectory() + "/unzipped/"; 
        /////////////////////////////////////////////////////////////////////

        try  { 

            AssetManager mgr = getBaseContext().getAssets();

            FileInputStream fin = (FileInputStream)mgr.open("totalkeys.zip");
            // throws ERROR/Decompress(24122): java.lang.ClassCastException: android.content.res.AssetManager$AssetInputStream

            //FileInputStream fin = new FileInputStream(_zipFile); /// old one, that wanted a String.
            ZipInputStream zin = new ZipInputStream(fin); 
            ZipEntry ze = …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
1万
查看次数

将图像从SurfaceView获取到ImageView?

我从使用SurfaceView作为相机preivew获取图像/可绘制或位图时遇到了一些麻烦.

    final CameraSurfaceView cameraSurfaceView = new CameraSurfaceView(this);
    LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout1);
    ll.addView(cameraSurfaceView); // THIS WORKS

    ImageView ivCam = (ImageView) findViewById(R.id.ivCam);
    ivCam.setImageBitmap(cameraSurfaceView.getDrawingCache()); // THIS DOESN'T :(
Run Code Online (Sandbox Code Playgroud)

有什么建议?谢谢!

编辑:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final CameraSurfaceView cameraSurfaceView = new CameraSurfaceView(this);
        LinearLayout ll = (LinearLayout)findViewById(R.id.LLS);
        ll.addView(cameraSurfaceView); // THIS WORKS


    }

///////////////////////////////////////////////////////////////////////////////////////////////   

    public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback
    {
            private SurfaceHolder holder;
            private Camera camera;

            public CameraSurfaceView(Context context) 
            {
                    super(context);

                    //Initiate the Surface Holder properly
                    this.holder = this.getHolder();
                    this.holder.addCallback(this);
                    this.holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
2万
查看次数

从互联网下载图像时在C#中进行多线程处理

我有一个从互联网加载图像的功能.然而,在加载时,我的应用程序无法执行任何其他操作.有没有解决的办法?

谢谢!

这是我的代码:

public static Bitmap BitmapFromWeb(string URL)
{
    try
    {
        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
        myRequest.Method = "GET";
        HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
        Bitmap bmp = new Bitmap(myResponse.GetResponseStream());
        myResponse.Close();
        return bmp;
    }
    catch (Exception ex)
    {
        return null;
    }
}


private void button1_Click(object sender, EventArgs e)
{
    load_avatrar();
}


private void load_avatrar()
{
    pictureBox_avatar.Image = BitmapFromWeb(avatral_url);
}
Run Code Online (Sandbox Code Playgroud)

c# multithreading

2
推荐指数
1
解决办法
1579
查看次数

WCF,用我的IP替换'localhost'还是应该使用NetTcpBinding?

在继续学习WCF的同时,我从http://msdn.microsoft.com/en-us/library/ms734712.aspx完成了入门教程并创建了我的第一个服务器/客户端应用程序.:)

但现在我想知道,如果我希望这个应用程序在不同的机器上运行,我该怎么办?

从服务器应用程序:

Uri baseAddress = new Uri("http://localhost:8000/Server");
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
Run Code Online (Sandbox Code Playgroud)

如果我想从外面获得这项服务,我该如何更换"localhost"?我尝试用我的IP替换它,但那不起作用.

有任何想法吗?

我还听说HttpBinding有点过时,主要用于wcf应用程序需要与非wcf应用程序通信时.而在wcf-to-wcf通信中应该使用NetTcpBinding,是这样的吗?

谢谢!:)

c# wcf

2
推荐指数
1
解决办法
4399
查看次数

C#,如何隐藏一种形式并显示另一种形式?

当我的项目启动 Form1 时加载并检查服务器的程序许可证,如果一切正常,它应该:显示 Form2 并关闭 Form1。之后,当用户用“x”关闭 Form2 时,程序应该结束。

你认为最好的方法是什么?

到目前为止只有 form2.Show :)

...
if (responseFromServer == "OK")
{
    Form2 form2 = new Form2();
    form2.Show();
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

.net c# winforms

2
推荐指数
2
解决办法
2万
查看次数

Sharedpreferences - 启动时崩溃

我正在尝试编写一个能够写入和读取共享偏好数据的活动.

我在开始时启动SharedPreferences

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Run Code Online (Sandbox Code Playgroud)

然后,此函数将一个int写入SP并调用另一个函数.

public void SetHue(int i)
{
    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt("storedInt", i); // value to store
    editor.commit();
    ApplyHue();
}
Run Code Online (Sandbox Code Playgroud)

这个其他函数应该从SP读取int ...

    public void ApplyHue()
    {   
    int hueInt = preferences.getInt("storedInt", 0);
    /// adjust background image hue according to hueInt.
    }
Run Code Online (Sandbox Code Playgroud)

我不能简单地将这个int从一个函数传递给另一个函数,因为我需要其他活动才能运行ApplyHue()函数,它应该从内存中使用hueInt.

您认为可能导致崩溃的原因是什么?

谢谢!

android sharedpreferences

2
推荐指数
1
解决办法
2145
查看次数

findViewById在InputMethodService中不起作用,我该怎么办?

我正在尝试创建一个Android键盘,这个代码到目前为止工作正常

package keyboard.rob.com;

import...

public class xyz extends InputMethodService 
implements KeyboardView.OnKeyboardActionListener {

    private LinearLayout mInputView;

    @Override public View onCreateInputView() {
        mInputView = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null);
        return mInputView;
    }

...
Run Code Online (Sandbox Code Playgroud)

但是后来当我想要做的时候

LinearLayout LinLayBg = (LinearLayout)findViewById(R.id.LL_total);
Run Code Online (Sandbox Code Playgroud)

它显示了用按钮填充它

"*方法findViewById(int)未定义类型zyz*"

有任何想法吗?谢谢!

java android

2
推荐指数
1
解决办法
479
查看次数

.innerHTML不工作或我使用它错了吗?

如果我理解正确,.innerHTML应该覆盖某个div或span中的任何内容.例如:

<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0">

  <tr>
    <td colspan="2" align="left">Via Email:</td>
    <td width="1070" align="right"></td>
  </tr>

  <script>
  $('#addEmail').click(function()       { 
document.getElementById('emailList').innerHTML = "12345";
  });  
  </script>

      <span  id="emailList">
   <tr>
    <td width="27" align="left"><img src="icon_mail.png" width="24" height="24"></td>
    <td width="228" align="left">123obama@whitehouse.com</td>
    <td align="right"><a href="#" id="dialog_link" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-close"></span>remove</a></td>
  </tr>
     </span>

  <tr>
    <td colspan="3" align="left"><br>
      <input name="input4" type="text" value="vova@kremlin.ru" size="20">      &nbsp;&nbsp;
      <a href="#" id="addEmail" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-mail-closed"></span>Add Email</a></td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

因此,点击#addEmail按钮后,内部的所有内容都将被删除并替换为"12345".

但实际上它并没有对那个跨度做任何事情,只是在脚本所在的地方打印出12345.

什么想法可能是错的?

javascript

1
推荐指数
1
解决办法
1250
查看次数

如何给LinearLayout充气(对于Android键盘)?

我正在尝试创建一个Android键盘,现在我只想从main.xml中膨胀,即show,linearlayout

这是java文件

package keyboard.rob.com;

import ...

public class zyz extends InputMethodService 
implements KeyboardView.OnKeyboardActionListener {

    private KeyboardView mInputView;

    @Override public void onCreate() {
        super.onCreate();
    }

    @Override public View onCreateInputView() {
        mInputView = (KeyboardView) getLayoutInflater().inflate(R.layout.main, null);
        return mInputView;
    }
}
Run Code Online (Sandbox Code Playgroud)

main.xml中

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:id="@+id/LL_whole" android:orientation="vertical" android:clickable="false">


    <LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@layout/backrep" android:layout_gravity="center" android:id="@+id/LL_total" android:orientation="vertical" android:layout_height="wrap_content">
        <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@drawable/spell_frame" android:layout_marginBottom="10px" android:layout_marginTop="5px" android:layout_gravity="center" android:id="@+id/LL_spell" android:paddingLeft="10px">
        </LinearLayout>


        <LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center" android:layout_width="wrap_content" android:id="@+id/LLrow1">

        </LinearLayout>
        <LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

java android

1
推荐指数
2
解决办法
3299
查看次数

读取unicode*.txt文件?

目前我正在阅读.txt文件

    FileInputStream is = new FileInputStream(masterPath+txt);
    BufferedReader br = new BufferedReader(new InputStreamReader(is));

    String readLine = null;

        while ((readLine = br.readLine()) != null) 
        {
        ...
Run Code Online (Sandbox Code Playgroud)

但unicode字符并不像它们应该的那样出现.

任何想法如何改变上面的代码,让unicode工作?

谢谢!

java android

1
推荐指数
1
解决办法
5399
查看次数